Currently, the only way to pass state between step definitions is by storing state as instance variables.
This is cumbersome in some languages, in particular for Java where it becomes tricky to share state between classes. DI is the only way to address this.
I would like to propose an alternative API for Step Definitions where:
This would remove the need for a World or DI. It would reduce coupling and make it more explicit what is passed between step definitions.
Once we're happy with the API we can create new issues to implement this in various Cucumbers.
(I've been thinking about this for a while, and I'm glad I am not the only one! See cucumber/cucumber-jvm#1136)
I think this solution trades a coupling a between step definitions and the World/DI modules for a coupling to the order in which steps in gherkin must be written. So I don't think this can be used to completely replace the World or DI modules. In the worst case you end up passing the World between steps.
For example take a website like Gmail that personalizes your account even when you are not logged in because it recognizes that nobody else ever uses that machine.
Given I am a specific kind of customer
And I have a login account that was previously used to login
When use the website
Then I am greeted with my name
In this scenario I'd have to pass the information about the customer (his name) from the first step all the way to last step through one or more steps that don't use the information.
But other then that yeah this can useful.
I found some past discussion about the same issue in Scala.
Edit: Wrong button. Sorry.