-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Provider instances with Pico Container #2879
Comments
I currently don't have much time to implement this. So if anyone wants to help out, that would be much appreciated. To implement this the following needs to be done.
cucumber-jvm/cucumber-spring/src/main/java/io/cucumber/spring/SpringBackend.java Lines 29 to 39 in 5abf447
|
On second thought. While the
So it might be nicer to declare a proper factory object: @Factory
public class WebDriverFactory {
private final Project project;
public WebDriverFactory(Project project) {
this.project = project;
}
@Bean
public WebDriver webDriver() {
return // create WebDriver
}
@Bean
public SecuredPage provide(WebDriver driver) {
return new SecuredPage(driver, project, "example", "top secret");
}
} But this isn't great either. Because now we have 2 annotations, to mark the factory class and methods involved. I'm also not sure if PicoContainer supports something like this. Or what circular dependencies might be created this way. This could be simplified a bit by requiring the factory methods to be static. public class WebDriverFactory {
@Bean
public static WebDriver webDriver() {
return // create WebDriver
}
@Bean
public static SecuredPage provide(WebDriver driver, Project project) {
return new SecuredPage(driver, project, "example", "top secret");
}
} But at point we may as well recommend that people use a fully featured DI such as Spring or Guice. Perhaps what we need instead are some good examples. |
🤔 What's the problem you're trying to solve?
Currently when using Cucumber with
cucumber-picocontainer
it is not possible to inject dependencies that that ultimately do not have a zero-argument constructor or require some setup. For example:For example
And it is also not possible to inject dependencies that partially depend on other inject dependencies and partially on some configuration.
For example we may want to inject
PageObjects
that partially depend on other dependencies and partially on some configuration:✨ What's your proposed solution?
Support Pico Containers
Providers
so that it becomes possible to write.⛏ Have you considered any alternatives or workarounds?
The current work around is to create a container object. But that quickly becomes ugly once multiple dependencies are involved. The other alternative is to use
cucumber-spring
orcucumber-guice
but both are quite complicated indeed.📚 Any additional context?
The text was updated successfully, but these errors were encountered: