The ScalaBackend from cucumber-scala currently instantiates all step classes directly rather than using the ObjectFactory approach that the JavaBackend uses.
Is there any possibility of introducing such support into the ScalaBackend? Alternatively, could the logic in the JavaBackend be extracted into some common library and reused?
What Scala DI framework would you like to use?
Guice would be my top choice but the JavaBackend does a good job of abstracting over the different DI libraries. If the same abstractions were used, the existing adapter libraries for each DI (guice, spring, picocontainer) could be reused.
Have you considered using cucumber-java instead and write classical stepdefs (similar to java) in scala?
If you are developing a hybrid Java/Scala application you should be able to write cucumber-java step definitions in Scala (as Aslak suggested) or use Java directly. If instead it is a pure Scala application you should consider native Scala DI using the language features instead of Java libraries.
@aslakhellesoy yes, I suppose this would work fine although cucumber-scala provides a nicer mechanism for defining steps than the annotations of cucumber-java. Are you reluctant to bring such support to the cucumber-scala library? I'd be happy to contribute a pull request.
@paoloambrosio what do you consider the language feature for having dependencies injected in to step definition classes? The cucumber-scala library relies on being able to instantiate step definition classes using a no argument constructor so there is no way to make dependencies available as construction arguments. I suppose the cake pattern could work since this allows for constructorless dependency injection but I get the impression that enough people are using dependency injection libraries with Scala for this to be worthwhile.
I'd be happy to take a pull request
@tobyclemson With "language features" I meant cake pattern, type classes and such. I am not a Scala expert, but I regret using Spring DI in a Scala project. Sorry, I thought Java DI was used only by people coming from Java background.
My impression from the comments here and in https://groups.google.com/d/topic/cukes/IF7Y1uqSxxU/discussion is that using DI containers with Scala is discouraged.
Shall we close this issue as "won't fix"?
SpringSource is working on a Scala port of their DI framework, but it hasn't been released yet. Perhaps once released, it could make sense to integrate that into Cucumber.
I'd say won'tfix this one until such thing is released, or if people ask for it again, once it's released. IMHO.
Won't fix! At least not for now.
If there's still interest in this feature, please take a look at my pull request.
Has anyone managed to utilize the cake pattern for injection with cucumber-jvm? In my opinion this would also need some changes in the ScalaBackend similar to the JavaBackend's ObjectFactory approach.
To revive dead threads, in the project I work on, we're using spring annotations to inject dependencies into scala classes. It does indeed just work.
Also, I have no idea how I "unassigned" someone .... all I did was comment :|
DI seems to be the only way to share state between steps, so cucumber-scala should support DI frameworks