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
Fix registration of contexts in Windsor and auto-register bindings #2187
Fix registration of contexts in Windsor and auto-register bindings #2187
Conversation
Component.For<ScenarioContext>().Instance(objectContainer.Resolve<ScenarioContext>()), | ||
Component.For<FeatureContext>().Instance(objectContainer.Resolve<FeatureContext>()), | ||
Component.For<TestThreadContext>().Instance(objectContainer.Resolve<TestThreadContext>())); | ||
container.Register(Component.For<T>().UsingFactoryMethod(objectContainer.Resolve<T>).LifestyleTransient()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LifestyleTransient
ensures the factory method is always called and forwards the resolution to IObjectContainer
.
|
||
RegisterSpecflowDependecies(args.ObjectContainer, container); | ||
|
||
args.ObjectContainer.RegisterInstanceAs(new WindsorScenarioScope(scope), dispose: true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way to end the Windsor scope is to dispose it. Let's just add a disposable object that will dispose the scope when the IObjectContainer
is disposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution!
As I have no idea about Winsor, I have to believe you that the changes are ok. |
Good idea, let me see if I can add some tests |
@SabotageAndi Added tests, can you take a look? |
Very nice! |
Sorry to bug @SabotageAndi, do you have time to release this out to Nuget? |
3.4.41-beta is out now. There was a problem with the release pipeline, but this is now fixed. |
Tested, thanks. I'm fine for this to be a non-beta release. |
This fixes the lifetime scope of the SpecFlow contexts (ScenarioContext etc), which wasn't working in the current version. This change also auto-registers the bindings, and uses Windsor's scope feature under the covers. Also added an example to the docs for using a shared container between scenarios/features.
Types of changes
Checklist: