-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add DI container support for contextual runners #59
Comments
Hey, you might want to check out SpecFlows BoDi container for a default integrated DI container. I am using it in psibr/REstate successfully with external DI support. It is pretty limited, but also easy to modify as I did to support IEnumerable resolutions. |
Hello @psibernetic . I have just recently came to this ticket to think how to implement it. I have got a basic DI working which will be shipped with LightBDD 2.4.0, and added LightBDD.Autofac project with sample integration with Autofac. Hopefully, over the time there will be more integrations with other people favourite DIs. There is still a lot of docs and samples to be written before shipping 2.4.0, but it should appear soon :) |
Very good sir, looking forward to it. |
* Implemented BasicDependencyContainer and wired it up to LightBDD * Added LightBDD.Autofac * Implemented WithContext<T>() to use DI * Updated containers to register self * Updated BasicDependencyContainer to use parameterized ctors for resolving items * Extended FeatureCoordinator to dispose DI container upon disposal * Implemented ResourcePool and ResourceProvider * Exposed DependencyResolver and Context on IScenario and IStep interfaces * Added EnableCurrentScenarioTracking() feature configuration. * Added StepExecution.GetScenarioDependencyResolver() extension method
The feature has been implemented on develop branch and will be released with LightBDD 2.4.0 |
Progress
Description
At this moment it is possible to specify
Runner.WithContext<MyContext>()
to use contextful runner with context having parameterless constructor. If context has dependencies, it has to be manually instantiated with code likeRunner.WithContext(new MyContext(dependency))
, and all dependencies has to be resolved manually in code. Finally, the contexts implementingIDisposable
interfaces are not disposed after usage.Initial Idea
Story definition
After spike, I have decided to add DI container support to LightBDD with focus on supporting proper, mature DIs but also provide a very basic DI in LightBDD itself.
Features:
LightBDDConfiguration.DependencyContainerConfiguration()
configuration allowing to specify DI container type and configure it,LightBDD.Autofac
project offering integration with Autofac,WithContext<TContext>()
extension methods to use DI containers and liftingwhere TContext: new()
constraint,StepExecution.Current.GetScenarioDependencyResolver()
extensions to allow retrieving DI resolver during scenario execution,ResourcePool<T>
type for handling resource pools (DI friendly),The text was updated successfully, but these errors were encountered: