#33: implement typedRegistrationBase and IOnCreate

pull/37/head
Simon Gockner 6 years ago
parent ad0c53189b
commit b1387dfbe8
  1. 8
      LightweightIocContainer/Interfaces/Registrations/IDefaultRegistration.cs
  2. 23
      LightweightIocContainer/Registrations/DefaultRegistration.cs

@ -3,6 +3,7 @@
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using LightweightIocContainer.Interfaces.Registrations.FluentProviders;
namespace LightweightIocContainer.Interfaces.Registrations
{
@ -10,11 +11,8 @@ namespace LightweightIocContainer.Interfaces.Registrations
/// The <see cref="IDefaultRegistration{TInterface}"/> to register a <see cref="Type"/> for the Interface it implements
/// </summary>
/// <typeparam name="TInterface">The <see cref="Type"/> of the interface</typeparam>
public interface IDefaultRegistration<TInterface> : IRegistrationBase<TInterface>
public interface IDefaultRegistration<TInterface> : ITypedRegistrationBase<TInterface>, IOnCreate<TInterface>
{
/// <summary>
/// The <see cref="Type"/> that implements the <see cref="IRegistration.InterfaceType"/> that is registered with this <see cref="IRegistrationBase{TInterface}"/>
/// </summary>
Type ImplementationType { get; }
}
}

@ -3,6 +3,7 @@
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using LightweightIocContainer.Interfaces.Installers;
using LightweightIocContainer.Interfaces.Registrations;
namespace LightweightIocContainer.Registrations
@ -11,7 +12,7 @@ namespace LightweightIocContainer.Registrations
/// The <see cref="DefaultRegistration{TInterface}"/> to register a <see cref="Type"/> for the Interface it implements
/// </summary>
/// <typeparam name="TInterface">The <see cref="Type"/> of the interface</typeparam>
public class DefaultRegistration<TInterface> : RegistrationBase<TInterface>, IDefaultRegistration<TInterface>
public class DefaultRegistration<TInterface> : TypedRegistrationBase<TInterface>, IDefaultRegistration<TInterface>
{
/// <summary>
/// The <see cref="DefaultRegistration{TInterface}"/> to register a <see cref="Type"/> for the Interface it implements
@ -20,15 +21,27 @@ namespace LightweightIocContainer.Registrations
/// <param name="implementationType">The <see cref="Type"/> of the implementation</param>
/// <param name="lifestyle">The <see cref="Lifestyle"/> of the <see cref="RegistrationBase{TInterface}"/></param>
public DefaultRegistration(Type interfaceType, Type implementationType, Lifestyle lifestyle)
: base(interfaceType, lifestyle)
: base(interfaceType, implementationType, lifestyle)
{
ImplementationType = implementationType;
Name = $"{InterfaceType.Name}, {ImplementationType.Name}, Lifestyle: {Lifestyle.ToString()}";
}
/// <summary>
/// The <see cref="Type"/> that implements the <see cref="RegistrationBase{TInterface}.InterfaceType"/> that is registered with this <see cref="RegistrationBase{TInterface}"/>
/// This <see cref="Action{T}"/> is invoked when an instance of this type is created.
/// <para>Can be set in the <see cref="IIocInstaller"/> by calling <see cref="OnCreate"/></para>
/// </summary>
public Type ImplementationType { get; }
public Action<TInterface> OnCreateAction { get; private set; }
/// <summary>
/// Pass an <see cref="Action{T}"/> that will be invoked when an instance of this <see cref="Type"/> is created
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="IRegistrationBase{TInterface}"/></returns>
public IRegistrationBase<TInterface> OnCreate(Action<TInterface> action)
{
OnCreateAction = action;
return this;
}
}
}
Loading…
Cancel
Save