cucumber-scala does not support DI libraries. #469

Closed
tobyclemson opened this Issue Mar 3, 2013 · 16 comments

Comments

Projects
None yet
7 participants

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?

Thanks,
Toby

Member

paoloambrosio commented Mar 3, 2013

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.

Owner

aslakhellesoy commented Mar 4, 2013

Have you considered using cucumber-java instead and write classical stepdefs (similar to java) in scala?

Member

paoloambrosio commented Mar 4, 2013

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.

Owner

aslakhellesoy commented Mar 4, 2013

I'd be happy to take a pull request

Member

paoloambrosio commented Mar 4, 2013

@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.

Owner

aslakhellesoy commented Sep 2, 2013

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"?

Member

paoloambrosio commented Sep 2, 2013

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.

Member

dkowis commented Sep 4, 2013

I'd say won'tfix this one until such thing is released, or if people ask for it again, once it's released. IMHO.

Owner

aslakhellesoy commented Sep 4, 2013

Won't fix! At least not for now.

If there's still interest in this feature, please take a look at my pull request.
#601

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.

Member

dkowis commented May 25, 2015

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.

skipoleschris was unassigned by dkowis May 25, 2015

Member

dkowis commented May 25, 2015

Also, I have no idea how I "unassigned" someone .... all I did was comment :|

austek commented Sep 15, 2016

DI seems to be the only way to share state between steps, so cucumber-scala should support DI frameworks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment