diff --git a/Test.LightweightIocContainer/SingleTypeRegistrationTest.cs b/Test.LightweightIocContainer/SingleTypeRegistrationTest.cs index 7f2beff..969663e 100644 --- a/Test.LightweightIocContainer/SingleTypeRegistrationTest.cs +++ b/Test.LightweightIocContainer/SingleTypeRegistrationTest.cs @@ -15,7 +15,13 @@ namespace Test.LightweightIocContainer; // ReSharper disable MemberHidesStaticFromOuterClass public class SingleTypeRegistrationTest { - private interface IFoo + [UsedImplicitly] + public interface IFooFactory + { + IFoo Create(IBar bar); + } + + public interface IFoo { IBar Bar { get; } } @@ -68,4 +74,20 @@ public class SingleTypeRegistrationTest Assert.IsInstanceOf(foo); Assert.AreEqual(bar, foo.Bar); } + + [Test] + public void TestSingleTypeRegistrationSingletonFactoryMethodOnlyCalledOnce() + { + IocContainer container = new(); + + IBar bar = new Bar(); + IFooFactory fooFactory = Substitute.For(); + + container.Register(r => r.Add(Lifestyle.Singleton).WithFactoryMethod(_ => fooFactory.Create(bar))); + + container.Resolve(); + container.Resolve(); + + fooFactory.Received(1).Create(Arg.Any()); + } } \ No newline at end of file