Erik Stroeken
Erik Stroeken

Reputation: 559

SpecFlow: how to inject ScenarioContext when NInject is used as IoC

After updating our solution from SpecFlow1.9 to 2.0 and NUnit2.6.4 to 3.2.1 we get a SpecFlowException when the SpecFlow tests are executed with NCrunch

TechTalk.SpecFlow.SpecFlowException : The ScenarioContext.Current static accessor cannot
 be used in multi-threaded execution. Try injecting the scenario context to the binding
 class. See http://go.specflow.org/doc-multithreaded for details.
 at TechTalk.SpecFlow.ScenarioContext.get_Current()

The solution the link http://go.specflow.org/doc-multithreaded in the exception text suggests only works when you use the build-in mini IoC of SpecFlow. However, we use NInject as IoC in our SpecFlow tests. Just wrapping the static field ScenarionContext.Current in a class and registering that class in a singleton context of course just moves the problem to another place.

Does anybody knows how to inject the ScenarionContext when NInject is used instead of the build-in IoC of SpecFlow?

Upvotes: 1

Views: 667

Answers (1)

Robert Kolski
Robert Kolski

Reputation: 11

SpecFlow now supports other containers via plugins for each container. Only one container can be used as it is injected into SpecFlows container. So if you use the Ninject plugin, then you can only use the Ninject plugin.

Unfortunately the developer who created the Ninject plugin did not publish it to NuGet so you'll have to build it yourself.

https://github.com/MattMcKinney/SpecFlow.Ninject

And you might want to ask him which license his plugin is using.

Upvotes: 1

Related Questions