Comments (8)
Unfortunately I won't be patching the current version, all my available time will be focused on the v4 release (first version is in preview right now). If you want to complete negate the disposing of classes I'd recommend trying v3.9.2
. I have no knowledge of the Specflow v4 release timeline, I'm just trying to keep up with their betas.
Sorry for the inconvenience.
from specflow.dependencyinjection.
Basically you need link IServiceCollection
lifetime with BoDi container lifetime.
Register relay disposers directly into container from arguments with dispose: true
on RuntimePluginEvents.CustomizeScenarioDependencies
and RuntimePluginEvents.CustomizeFeatureDependencies
events.
Example:
internal class SpecFlowRuntimePlugin : IRuntimePlugin
{
public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters, UnitTestProviderConfiguration unitTestProviderConfiguration)
{
runtimePluginEvents.CustomizeFeatureDependencies += RuntimePluginEventsOnCustomizeFeatureDependencies;
runtimePluginEvents.CustomizeScenarioDependencies += RuntimePluginEventsOnCustomizeScenarioDependencies;
}
private void RuntimePluginEventsOnCustomizeFeatureDependencies(object sender, CustomizeFeatureDependenciesEventArgs e)
{
// Initialize child DI scope for feature
var disposer = new RelayDispose(() =>
{
// Dispose child DI scope here
});
e.ObjectContainer.RegisterInstanceAs(disposer, dispose: true);
}
private void RuntimePluginEventsOnCustomizeScenarioDependencies(object sender, CustomizeScenarioDependenciesEventArgs e)
{
// Initialize child DI scope for scenario
var disposer = new RelayDispose(() =>
{
// Dispose child DI scope here
});
e.ObjectContainer.RegisterInstanceAs(disposer, dispose: true);
}
}
public class RelayDispose : IDisposable
{
private readonly Action _disposeAction;
public RelayDispose(Action disposeAction)
{
_disposeAction = disposeAction;
}
public void Dispose()
{
_disposeAction?.Invoke();
}
}
I will create PR if you are still supporting this package. Please, let me know.
from specflow.dependencyinjection.
Hey @BlackGad, thanks for reporting this issue. These changes were introduced in #74 and in hindsight I should've had a better understanding of it before merging. For the next major release (aiming for right after they release SpecFlow v4) I'll be reworking a lot of these changes, and I'm also going to bring it more in line with how the official Autofac plugin works (e.g. they introduced a a [FeatureDependencies]
tag for scoping to features).
Having said that I will consider your solution because it makes a lot of sense, so I'm adding it to the milestone. No need for a PR because the code will probably change a lot before release. Thanks again!
from specflow.dependencyinjection.
Thank you! But it is crucial issue for me right now :) Is there any chance to provide patch to current released version?
And happy new year!
from specflow.dependencyinjection.
Btw do you know specflow 4 release date?
from specflow.dependencyinjection.
Is this a bug or a feature?
I'm trying to move from AdCodicem.SpecFlow.MicrosoftDependencyInjection, but I get mulitple scope/dispose issues which are hard to find out. (locally it works, on CI it fails)
from specflow.dependencyinjection.
@304NotModified Hmm, weird that it works locally but fails in CI -- sounds like a bug. Would you be willing to check against v3.9.2
and see if that changes anything? Migration from AdCodicem's plugin is still an outstanding issue (#86).
I am looking to fix most of the async and disposable problems with the release of SpecFlow v4 (they did a lot of work in there which I depend on), but unfortunately the release of v4 (or even the current state of SpecFlow) seems very unclear atm.
from specflow.dependencyinjection.
Related Issues (20)
- Support for asynchronous creation of service collection HOT 2
- AddHttpMessageHandler throwing an exception HOT 6
- Concurrency issue when using Amazon.Extensions.Configuration.SystemsManager HOT 5
- Add Package Validation HOT 1
- Request: Support for Microsoft.Extensions.DependencyInjection <= Version 3.1.18 HOT 3
- After ScenarioContext class is used in steps, disposal fails. HOT 2
- Support .NET 6 HOT 1
- Unable to resolve IUnitTestRuntimeProvider
- ITestOutputHelper unavailable when using SpecFlow.xUnit HOT 16
- Tests ran in parallel clash with each other HOT 4
- How to use TestRunContext for inject configuration HOT 1
- Improve README basic example HOT 1
- Change CD to make pre-releases available
- Migration path for AdCodicem's plugin HOT 1
- The given key 'Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope' was not present in the dictionary. HOT 8
- [ScenarioDependencies] replaces DI implementation of the framework or the library(s) HOT 2
- The type 'ServiceCollection' exists in both 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.Extensions.DependencyInjection, Version=3.1.0.0 HOT 3
- RegisterProxyBindings does not register step context HOT 1
- Evaluate [FeatureDependencies] HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from specflow.dependencyinjection.