diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs index 7124db7..17155f9 100644 --- a/LightweightIocContainer/IocContainer.cs +++ b/LightweightIocContainer/IocContainer.cs @@ -167,16 +167,9 @@ public class IocContainer : IIocContainer, IIocResolver if (registration is IWithParametersInternal { Parameters: { } } registrationWithParameters) arguments = UpdateArgumentsWithRegistrationParameters(registrationWithParameters, arguments); - List? resolveArguments = arguments?.ToList(); - if (resolveArguments != null && registration is IMultitonRegistration multitonReg) //remove scope argument for multitions - { - object multitonScopeArgument = TryGetMultitonScopeArgument(multitonReg, resolveArguments); - resolveArguments.Remove(multitonScopeArgument); - } - Type registeredType = GetType(registration); (bool result, List? parametersToResolve, NoMatchingConstructorFoundException? exception) = - TryGetTypeResolveStack(registeredType, resolveArguments, internalResolveStack); + TryGetTypeResolveStack(registeredType, arguments, internalResolveStack); if (registration is IMultitonRegistration multitonRegistration) { diff --git a/Test.LightweightIocContainer/DisposeStrategyTest.cs b/Test.LightweightIocContainer/DisposeStrategyTest.cs index 6ffdb4a..2572e9c 100644 --- a/Test.LightweightIocContainer/DisposeStrategyTest.cs +++ b/Test.LightweightIocContainer/DisposeStrategyTest.cs @@ -23,6 +23,14 @@ public class DisposeStrategyTest public void Dispose() => throw new Exception(); } + private class TestMultiton : Test + { + public TestMultiton(int scope) + { + + } + } + private class TestNotDisposable { @@ -44,7 +52,7 @@ public class DisposeStrategyTest public void TestValidContainerDisposeStrategyMultiton() { IocContainer iocContainer = new(); - iocContainer.Register(r => r.AddMultiton().WithDisposeStrategy(DisposeStrategy.Container)); + iocContainer.Register(r => r.AddMultiton().WithDisposeStrategy(DisposeStrategy.Container)); iocContainer.Resolve(1); @@ -66,7 +74,7 @@ public class DisposeStrategyTest public void TestValidAppDisposeStrategyMultiton() { IocContainer iocContainer = new(); - iocContainer.Register(r => r.AddMultiton().WithDisposeStrategy(DisposeStrategy.Application)); + iocContainer.Register(r => r.AddMultiton().WithDisposeStrategy(DisposeStrategy.Application)); iocContainer.Resolve(1); diff --git a/Test.LightweightIocContainer/FluentFactoryRegistrationTest.cs b/Test.LightweightIocContainer/FluentFactoryRegistrationTest.cs index 095061c..6b40e5f 100644 --- a/Test.LightweightIocContainer/FluentFactoryRegistrationTest.cs +++ b/Test.LightweightIocContainer/FluentFactoryRegistrationTest.cs @@ -101,6 +101,14 @@ public class FluentFactoryRegistrationTest public ITest CreateTest(string name = null) => throw new NotImplementedException(); public ITest Create(byte id) => throw new NotImplementedException(); } + + public class TestMultiton : ITest + { + public TestMultiton(MultitonScope scope) + { + + } + } [UsedImplicitly] public interface IMultitonTestFactory @@ -290,7 +298,7 @@ public class FluentFactoryRegistrationTest [Test] public void TestResolveMultitonFromFactory() { - _iocContainer.Register(r => r.AddMultiton().WithFactory()); + _iocContainer.Register(r => r.AddMultiton().WithFactory()); MultitonScope scope1 = new(); MultitonScope scope2 = new(); @@ -309,7 +317,7 @@ public class FluentFactoryRegistrationTest [Test] public void TestResolveMultitonFromFactoryClearInstances() { - _iocContainer.Register(r => r.AddMultiton().WithFactory()); + _iocContainer.Register(r => r.AddMultiton().WithFactory()); MultitonScope scope1 = new(); MultitonScope scope2 = new(); diff --git a/Test.LightweightIocContainer/IocContainerTest.cs b/Test.LightweightIocContainer/IocContainerTest.cs index 31a6eca..b65a67d 100644 --- a/Test.LightweightIocContainer/IocContainerTest.cs +++ b/Test.LightweightIocContainer/IocContainerTest.cs @@ -26,6 +26,14 @@ public class IocContainerTest { } + + private class TestMultiton : ITest + { + public TestMultiton(MultitonScope multitonScope) + { + + } + } [UsedImplicitly] private class TestConstructor : ITest @@ -248,7 +256,7 @@ public class IocContainerTest [Test] public void TestResolveMultiton() { - _iocContainer.Register(r => r.AddMultiton()); + _iocContainer.Register(r => r.AddMultiton()); MultitonScope scope1 = new(); MultitonScope scope2 = new(); diff --git a/Test.LightweightIocContainer/MultipleMultitonRegistrationTest.cs b/Test.LightweightIocContainer/MultipleMultitonRegistrationTest.cs index 1a89ef7..da0c169 100644 --- a/Test.LightweightIocContainer/MultipleMultitonRegistrationTest.cs +++ b/Test.LightweightIocContainer/MultipleMultitonRegistrationTest.cs @@ -26,8 +26,13 @@ public class MultipleMultitonRegistrationTest } [UsedImplicitly] - public class Test : ITest + private class Test : ITest { + public Test(MultitonScope scope) + { + + } + public int Number { get; private set; } public void DoSomething(int number) => Number = number;