diff --git a/LightweightIocContainer/Interfaces/Registrations/IRegistrationBase.cs b/LightweightIocContainer/Interfaces/Registrations/IRegistrationBase.cs index 69179ed..e8ba70e 100644 --- a/LightweightIocContainer/Interfaces/Registrations/IRegistrationBase.cs +++ b/LightweightIocContainer/Interfaces/Registrations/IRegistrationBase.cs @@ -6,11 +6,19 @@ using LightweightIocContainer.Interfaces.Registrations.FluentProviders; namespace LightweightIocContainer.Interfaces.Registrations { + /// + /// A base without generic interface + /// + public interface IRegistrationBase : IRegistration, ILifestyleProvider + { + + } + /// /// The that is used to register an Interface /// /// The registered Interface - public interface IRegistrationBase : IRegistration, ILifestyleProvider, IWithParameters + public interface IRegistrationBase : IRegistrationBase, IWithParameters { } diff --git a/LightweightIocContainer/Interfaces/Registrations/ITypedRegistrationBase.cs b/LightweightIocContainer/Interfaces/Registrations/ITypedRegistrationBase.cs index 9c7e902..e5752fa 100644 --- a/LightweightIocContainer/Interfaces/Registrations/ITypedRegistrationBase.cs +++ b/LightweightIocContainer/Interfaces/Registrations/ITypedRegistrationBase.cs @@ -8,15 +8,23 @@ using LightweightIocContainer.Interfaces.Registrations.FluentProviders; namespace LightweightIocContainer.Interfaces.Registrations { /// - /// A base without implementation + /// A base without generic interface and implementation /// - public interface ITypedRegistrationBase : IRegistrationBase + public interface ITypedRegistrationBase : IRegistrationBase { /// /// The that implements the that is registered with this /// Type ImplementationType { get; } } + + /// + /// A base without generic implementation + /// + public interface ITypedRegistrationBase : IRegistrationBase, ITypedRegistrationBase + { + + } /// /// A that implements a diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs index 67a1b77..a01c073 100644 --- a/LightweightIocContainer/IocContainer.cs +++ b/LightweightIocContainer/IocContainer.cs @@ -301,7 +301,7 @@ namespace LightweightIocContainer T resolvedInstance; - if (registration is IRegistrationBase defaultRegistration) + if (registration is IRegistrationBase defaultRegistration) { if (defaultRegistration.Lifestyle == Lifestyle.Singleton) resolvedInstance = GetOrCreateSingletonInstance(defaultRegistration, arguments, resolveStack); @@ -413,11 +413,11 @@ namespace LightweightIocContainer /// A newly created instance of the given private T CreateInstance(IRegistration registration, object[] arguments, List resolveStack) { - if (registration is IWithParameters registrationWithParameters && registrationWithParameters.Parameters != null) + if (registration is IWithParameters { Parameters: { } } registrationWithParameters) arguments = UpdateArgumentsWithRegistrationParameters(registrationWithParameters, arguments); T instance; - if (registration is ITypedRegistrationBase defaultRegistration) + if (registration is ITypedRegistrationBase defaultRegistration) { arguments = ResolveConstructorArguments(defaultRegistration.ImplementationType, arguments, resolveStack); instance = (T) Activator.CreateInstance(defaultRegistration.ImplementationType, arguments); @@ -587,6 +587,10 @@ namespace LightweightIocContainer IRegistration registration = _registrations.FirstOrDefault(r => r.InterfaceType == typeof(T)); if (registration != null) return registration; + + registration = _registrations.OfType().FirstOrDefault(r => r.ImplementationType == typeof(T)); + if (registration != null) + return registration; //check for open generic registration if (!typeof(T).GenericTypeArguments.Any()) diff --git a/LightweightIocContainer/LightweightIocContainer.xml b/LightweightIocContainer/LightweightIocContainer.xml index a87768a..1123293 100644 --- a/LightweightIocContainer/LightweightIocContainer.xml +++ b/LightweightIocContainer/LightweightIocContainer.xml @@ -690,6 +690,11 @@ The of the Interface that is registered with this + + + A base without generic interface + + The that is used to register an Interface @@ -725,16 +730,21 @@ The class that contains the implemented abstract factory of this - + - A base without implementation + A base without generic interface and implementation - + The that implements the that is registered with this + + + A base without generic implementation + + A that implements a diff --git a/Test.LightweightIocContainer/IocContainerTest.cs b/Test.LightweightIocContainer/IocContainerTest.cs index 19c22a0..f8efff4 100644 --- a/Test.LightweightIocContainer/IocContainerTest.cs +++ b/Test.LightweightIocContainer/IocContainerTest.cs @@ -211,6 +211,16 @@ namespace Test.LightweightIocContainer _iocContainer.Register(); Assert.Throws(() => _iocContainer.Resolve()); } + + [Test] + public void TestResolveImplementationRegisteredWithInterface() + { + _iocContainer.Register(); + + Test resolvedTest = _iocContainer.Resolve(); + + Assert.IsInstanceOf(resolvedTest); + } [Test] public void TestResolveWithParams()