Improve Dependency injection scopes
See original GitHub issueHi,
just trying to get one thing done and having some difficulties.
According to this each scenario has it’s own scope but additional scopes get created for composite steps.
How do I properly share a dependency between my top-level steps and steps which are in a composite step and use their own context?
Top-level steps are using StepExecution.Current.GetScenarioDependencyResolver().Resolve<T>()
to inject a dependency and context uses constructor injection. Unfortunately I get two different instances while I’d like to share session state throughout entire scenario.
The docs say Finally, container scopes are hierarchical, which means that they are aware of their parent and depending on configuration can use dependencies specified in higher scopes for injections.
Can it be achieved using default DI container or only by applying a custom one which can handle scopes other than transient or singleton?
Maybe there is also a different way to share state between contexts for instance? I haven’t found a proper example for that. I can’t use neither of the methods described here because they only solve state sharing inside one “scope” (either context or a fixture class).
I come more from SpecFlow world and there was something like ScenarioContext
which is basically a bag for anything that you want to share between steps no matter where the steps are defined.
I can’t find a good way to achieve something similar in LightBDD.
Well… I can imagine reimplementing a concept of ScenarioContext
using AutoFac but don’t want to reinvent the wheel. Maybe it can be done without 3rd party DI?
Issue Analytics
- State:
- Created 3 years ago
- Comments:13
Top GitHub Comments
Works like a charm! Thanks again.
I have also update the wiki to provide more details about sharing state with composite steps: https://github.com/LightBDD/LightBDD/wiki/Scenario-State-Management#sharing-state-with-composite-steps