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!
consider this testcase:
I just accidentally hit this because I was changing a couple of reuses. This should ideally fail with verification!