Skip to content

Commit 98ec6a3

Browse files
committed
Document ServiceProviderLifetimeType configuration in CHANGELOG and DI integration guide.
1 parent e64ce7f commit 98ec6a3

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
## Improvements:
44

5+
* Microsoft.Extensions.DependencyInjection.ReqnrollPlugin: Added support for configurable service provider lifetimes to control at which scope the services are registered (#998)
6+
* Options are Global (default, previous behavior), Test Thread, Feature, Scenario
7+
58
## Bug fixes:
69

7-
*Contributors of this release (in alphabetical order):*
10+
*Contributors of this release (in alphabetical order):* @AidenFuller
811

912
# v3.3.1 - 2026-01-08
1013

docs/integrations/dependency-injection.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ Reqnroll plugin for using Microsoft.Extensions.DependencyInjection as a dependen
77
Currently supports Microsoft.Extensions.DependencyInjection v6.0.0 or above
88
```
99

10-
## Step by step walkthrough of using Reqnroll.Microsoft.Extensions.DependencyInjection
10+
## Install the plugin from NuGet into your Reqnroll project
1111

12+
Install the `Reqnroll.Microsoft.Extensions.DependencyInjection` NuGet package directly into your test project.
1213

13-
### 1. Install plugin from NuGet into your Reqnroll project.
14-
15-
```csharp
16-
PM> Install-Package Reqnroll.Microsoft.Extensions.DependencyInjection
14+
```powershell
15+
Install-Package Reqnroll.Microsoft.Extensions.DependencyInjection
1716
```
18-
### 2. Create static methods somewhere in the Reqnroll project
1917

20-
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.
21-
22-
### 3. A typical dependency builder method looks like this:
18+
## Using the plugin
19+
20+
Create a static, parameterless method in your Reqnroll project that returns an instance of `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 Reqnroll `[Binding]` attribute) are automatically added to the service collection.
21+
22+
A typical dependency builder method looks like this:
2323

2424
```csharp
2525
public class SetupTestDependencies
@@ -36,3 +36,23 @@ public class SetupTestDependencies
3636
}
3737
}
3838
```
39+
40+
### Configuring the scope and lifetime of the service provider
41+
42+
For services registered with a scoped lifetime (as opposed to singleton), it might make sense to have a new scope for each scenario rather than each feature (the default). If this is the case, this can be adjusted with the `ScopeLevel` property on the `[ScenarioDependencies]` attribute. For example
43+
44+
```csharp
45+
[ScenarioDependencies(ScopeLevel = ScopeLevelType.Scenario)]
46+
public static IServiceCollection CreateServices()
47+
```
48+
49+
It's also possible to change the lifetime of the entire service provider, rather than just its scope. This is particularly useful when you want a new instance of a singleton service for each feature or each scenario.
50+
51+
```csharp
52+
[ScenarioDependencies(ServiceProviderLifetime = ServiceProviderLifetimeType.Feature)]
53+
public static IServiceCollection CreateServices()
54+
```
55+
56+
```{note}
57+
If the `ServiceProviderLifetime` is set to `Scenario` then the `ScopeLevel` is implicitly `Scenario` as well.
58+
```

0 commit comments

Comments
 (0)