Warning
This plugin has been ported to Reqnroll and will no longer be maintained.
SpecFlow plugin that enables to use Microsoft.Extensions.DependencyInjection for resolving test dependencies.
Currently supports (in preview):
- SpecFlow v4 or above
- Microsoft.Extensions.DependencyInjection v6.0.0 or above
Based on SpecFlow.Autofac. Listed on Available Plugins for SpecFlow.
Install plugin from NuGet into your SpecFlow project.
PM> Install-Package SolidToken.SpecFlow.DependencyInjection
Create a static method in your SpecFlow project that returns a Microsoft.Extensions.DependencyInjection.IServiceCollection
and tag it with the [ScenarioDependencies]
attribute.
Configure your test dependencies for the scenario execution within this method.
Step definition classes (i.e. classes with the SpecFlow [Binding]
attribute) are automatically added to the service collection.
A typical dependency builder method looks like this:
[ScenarioDependencies]
public static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
// TODO: add your test dependencies here
return services;
}
Refer to SpecFlow.DependencyInjection.Tests
for an example.