Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDisposable on Scope doesn't call Dispose on cached instances #1

Closed
davidmatson opened this issue Jul 12, 2018 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@davidmatson
Copy link
Contributor

Based on reading the code; haven't tested, but I think the repro would be something like:

class SpyDisposable : IDisposable
{
    public bool Disposed { get; private set; }

    public void Dispose()
    {
        Disposed = true;
    }
}

Container.Register<SpyDisposable>(typeof(SpyDisposable));
SpyDisposable spy;

using (var scope = Container.CreateScope())
{
    spy = scope.Resolve<SpyDisposable>();
}

Assert.True(spy.Disposed);
@vladris vladris self-assigned this Jul 12, 2018
@vladris vladris added the bug Something isn't working label Jul 12, 2018
@vladris
Copy link
Member

vladris commented Jul 12, 2018

Note there is a small bug in the repro above. SpyDisposable should be registered as PerScope, otherwise the container won't hold on to the resolved instance:

-Container.Register<SpyDisposable>(typeof(SpyDisposable));
+Container.Register<SpyDisposable>(typeof(SpyDisposable)).PerScope();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants