Skip to content

Commit

Permalink
fixed: #516
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Aug 9, 2022
1 parent 84a5137 commit 83da3c2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DryIoc/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9892,7 +9892,7 @@ public Request WithResolvedFactory(Factory factory,
scopedOrSingleton && p.Reuse is SingletonReuse ||
p.FactoryType == FactoryType.Wrapper && p._actualServiceType.IsFunc())
checkCaptiveDependency = false; // stop the check
else if (p.FactoryType == FactoryType.Service && p.ReuseLifespan > reuseLifespan)
else if (p.FactoryType != FactoryType.Wrapper && p.ReuseLifespan > reuseLifespan)
Throw.It(Error.DependencyHasShorterReuseLifespan, PrintCurrent(), reuse, p);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using NUnit.Framework;

namespace DryIoc.IssuesTests
{
[TestFixture]
public class GHIssue516_Singleton_Decorator_to_Scoped_base_should_not_work_but_does : ITest
{
public int Run()
{
Example();
return 1;
}

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

using (var s1 = c.OpenScope())
{
var ex = Assert.Throws<ContainerException>(() => s1.Resolve<IFace>());
Assert.AreEqual(Error.NameOf(Error.DependencyHasShorterReuseLifespan), ex.ErrorName);
}
}

public interface IFace { }

public class A : IFace { }

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

0 comments on commit 83da3c2

Please sign in to comment.