-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...Ioc.IssuesTests/GHIssue516_Singleton_Decorator_to_Scoped_base_should_not_work_but_does.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |