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

Singleton Decorator to Scoped base shouldn't work, but does #516

Closed
hutterm opened this issue Aug 8, 2022 · 2 comments
Closed

Singleton Decorator to Scoped base shouldn't work, but does #516

hutterm opened this issue Aug 8, 2022 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@hutterm
Copy link

hutterm commented Aug 8, 2022

consider this testcase:

    public interface IFace{}

    public class A : IFace { }

    public class ADecorator : IFace
    {
        public IFace Inner { get; }
        public ADecorator(IFace inner)
        {
            Inner = inner;
        }
    }

    [Fact]
    public void CanRegisterSingletonDecoratorToScoped()
    {
        var c = new Container();
        c.RegisterMany<A>(Reuse.Scoped);
        c.Register<IFace, ADecorator>(Reuse.Singleton, setup: Setup.Decorator);

        using (var s1=c.OpenScope())
        {
            var f = s1.Resolve<IFace>();
            f.Should().BeOfType<ADecorator>();
            s1.Resolve<A>().Should().Be(((ADecorator)f).Inner);
        }

        using (var s2=c.OpenScope())
        {
            var f = s2.Resolve<IFace>();
            f.Should().BeOfType<ADecorator>();
            s2.Resolve<A>().Should().Be(((ADecorator)f).Inner); //throws because inner is A from the s1 scope!!!
        }
    }

I just accidentally hit this because I was changing a couple of reuses.
This should ideally fail with verification!

@dadhi
Copy link
Owner

dadhi commented Aug 9, 2022

@hutterm Thanks for the test, will look.

@dadhi dadhi closed this as completed in 83da3c2 Aug 9, 2022
@dadhi dadhi self-assigned this Aug 9, 2022
@dadhi dadhi added the bug Something isn't working label Aug 9, 2022
@dadhi dadhi added this to the v5.2.1 milestone Aug 9, 2022
@dadhi
Copy link
Owner

dadhi commented Aug 9, 2022

@hutterm Hi, the fix is out with v5.2.1

dadhi added a commit that referenced this issue Aug 9, 2022
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