|
|
|
@ -2,6 +2,7 @@ |
|
|
|
// Created: 2019-05-20 |
|
|
|
// Created: 2019-05-20 |
|
|
|
// Copyright(c) 2019 SimonG. All Rights Reserved. |
|
|
|
// Copyright(c) 2019 SimonG. All Rights Reserved. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using LightweightIocContainer.Interfaces; |
|
|
|
using LightweightIocContainer.Interfaces; |
|
|
|
using LightweightIocContainer.Interfaces.Installers; |
|
|
|
using LightweightIocContainer.Interfaces.Installers; |
|
|
|
using LightweightIocContainer.Interfaces.Registrations; |
|
|
|
using LightweightIocContainer.Interfaces.Registrations; |
|
|
|
@ -37,6 +38,32 @@ namespace LightweightIocContainer.Registrations |
|
|
|
return new MultitonRegistration<TInterface>(typeof(TInterface), typeof(TImplementation), typeof(TScope)); |
|
|
|
return new MultitonRegistration<TInterface>(typeof(TInterface), typeof(TImplementation), typeof(TScope)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Register an Interface with a Type that implements it and create a <see cref="IDefaultRegistration{TInterface}"/> |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="tInterface">The Interface to register</param> |
|
|
|
|
|
|
|
/// <param name="tImplementation">The Type that implements the <see cref="tInterface"/></param> |
|
|
|
|
|
|
|
/// <param name="lifestyle">The <see cref="Lifestyle"/> for this <see cref="IDefaultRegistration{TInterface}"/></param> |
|
|
|
|
|
|
|
/// <returns>A new created <see cref="IDefaultRegistration{TInterface}"/> with the given parameters</returns> |
|
|
|
|
|
|
|
public static IRegistrationBase Register(Type tInterface, Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Type defaultRegistrationType = typeof(DefaultRegistration<>).MakeGenericType(tInterface); |
|
|
|
|
|
|
|
return (IRegistrationBase)Activator.CreateInstance(defaultRegistrationType, tInterface, tImplementation, lifestyle); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Register an Interface with a Type that implements it as a multiton and create a <see cref="IMultitonRegistration{TInterface}"/> |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="tInterface">The Interface to register</param> |
|
|
|
|
|
|
|
/// <param name="tImplementation">The Type that implements the <see cref="tInterface"/></param> |
|
|
|
|
|
|
|
/// <param name="tScope">The Type of the multiton scope</param> |
|
|
|
|
|
|
|
/// <returns>A new created <see cref="IMultitonRegistration{TInterface}"/> with the given parameters</returns> |
|
|
|
|
|
|
|
public static IRegistrationBase Register(Type tInterface, Type tImplementation, Type tScope) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Type multitonRegistrationType = typeof(MultitonRegistration<>).MakeGenericType(tInterface); |
|
|
|
|
|
|
|
return (IRegistrationBase)Activator.CreateInstance(multitonRegistrationType, tInterface, tImplementation, tScope); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Register an Interface as an abstract typed factory and create a <see cref="ITypedFactoryRegistration{TFactory}"/> |
|
|
|
/// Register an Interface as an abstract typed factory and create a <see cref="ITypedFactoryRegistration{TFactory}"/> |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
@ -47,5 +74,17 @@ namespace LightweightIocContainer.Registrations |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new TypedFactoryRegistration<TFactory>(typeof(TFactory), container); |
|
|
|
return new TypedFactoryRegistration<TFactory>(typeof(TFactory), container); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Register an Interface as an abstract typed factory and create a <see cref="ITypedFactoryRegistration{TFactory}"/> |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="tFactory">The abstract typed factory to register</param> |
|
|
|
|
|
|
|
/// <param name="container">The current <see cref="IIocContainer"/></param> |
|
|
|
|
|
|
|
/// <returns>A new created <see cref="ITypedFactoryRegistration{TFactory}"/> with the given parameters</returns> |
|
|
|
|
|
|
|
public static IRegistrationBase RegisterFactory(Type tFactory, IIocContainer container) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Type factoryRegistrationType = typeof(TypedFactoryRegistration<>).MakeGenericType(tFactory); |
|
|
|
|
|
|
|
return (IRegistrationBase)Activator.CreateInstance(factoryRegistrationType, tFactory, container); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |