GithubHelp home page GithubHelp logo

Comments (8)

mbhoek avatar mbhoek commented on May 28, 2024 1

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.

BlackGad avatar BlackGad commented on May 28, 2024

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.

mbhoek avatar mbhoek commented on May 28, 2024

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.

BlackGad avatar BlackGad commented on May 28, 2024

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.

BlackGad avatar BlackGad commented on May 28, 2024

Btw do you know specflow 4 release date?

from specflow.dependencyinjection.

304NotModified avatar 304NotModified commented on May 28, 2024

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.

mbhoek avatar mbhoek commented on May 28, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.