Skip to content
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

Merged
merged 9 commits into from Nov 2, 2020
Merged

Fix registration of contexts in Windsor and auto-register bindings #2187

merged 9 commits into from Nov 2, 2020

Conversation

robertcoltheart
Copy link
Contributor

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

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Performance improvement
  • Refactoring (so no functional change)
  • Other (docs, build config, etc)

Checklist:

  • I've added tests for my code. (most of the time mandatory)
  • I have added an entry to the changelog. (mandatory)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

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());
Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution!

@SabotageAndi
Copy link
Contributor

As I have no idea about Winsor, I have to believe you that the changes are ok.
Some tests/example project would be cool to have something to check if it is working.

@robertcoltheart
Copy link
Contributor Author

Good idea, let me see if I can add some tests

@robertcoltheart
Copy link
Contributor Author

@SabotageAndi Added tests, can you take a look?

@SabotageAndi
Copy link
Contributor

Very nice!

@SabotageAndi SabotageAndi merged commit a47d7f9 into SpecFlowOSS:master Nov 2, 2020
@robertcoltheart robertcoltheart deleted the feature/add-windsor-customization branch November 2, 2020 11:28
@robertcoltheart
Copy link
Contributor Author

Sorry to bug @SabotageAndi, do you have time to release this out to Nuget?

@SabotageAndi
Copy link
Contributor

3.4.41-beta is out now. There was a problem with the release pipeline, but this is now fixed.

@robertcoltheart
Copy link
Contributor Author

Tested, thanks. I'm fine for this to be a non-beta release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants