Skip to content

IRegistrationBase

Simon Gockner edited this page Oct 15, 2019 · 7 revisions

The IRegistrationBase is a base interface for all registration classes that are used to register interfaces with the IocContainer.

It consists only of two properties:

/// <summary>
/// The name of the <see cref="IRegistrationBase"/>
/// </summary>
string Name { get; }

and

/// <summary>
/// The <see cref="Type"/> of the Interface that is registered with this <see cref="IRegistrationBase"/>
/// </summary>
Type InterfaceType { get; }

All of the following implementations of the IRegistrationBase can be easily created by the RegistrationFactory.

IDefaultRegistration<TInterface>

This is the default registration that is used to register a Type for the interface it implements. TInterface is the Type of the interface.

In addition to the implemented properties from the IRegistrationBase the IDefaultRegistration adds the following properties and methods:

  • The Type that implements the IRegistrationBase.InterfaceType that gets registered

    Type ImplementationType { get; }
  • The Lifestyle of the registered Type

    Lifestyle Lifestyle { get; }
  • An Action that is invoked when an instance of the registered type is created

    Action<TInterface> OnCreateAction { get; }
  • A method to pass the OnCreateAction to the IDefaultRegistration

    IDefaultRegistration<TInterface> OnCreate(Action<TInterface> action);

IMultitonRegistration<TInterface>

The IMultitonRegistration is derived from the IDefaultRegistration and is used to register a Type that is of the Lifestyle.Multiton.

It adds only one property to the already overridden ones, the Type of the multiton scope:

Type Scope { get; }

ITypedFactoryRegistration<TFactory>

The ITypedFactoryRegistration is used to register an abstract typed factory with the IocContainer. TFactory is the Type of the factory.

It consists of the implemented properties from the IRegistrationBase and adds one property of its own, the class that contains the implemented abstract factory of this ITypedFactoryRegistration:

ITypedFactory<TFactory> Factory { get; }

The TypedFactoryRegistration<TFactory> class implements the ITypedFactoryRegistration<TFactory> interface and also handles the implementation of the abstract factories. Therefore it supplies the CreateFactory() method:

private void CreateFactory(IIocContainer container)
{

}

This is done by writing the IL code for the Create() methods manually that call the IocContainer.Resolve() method, as well as the ClearMultitonInstance method that calls the IocContainer.ClearMultitonInstances<>() method.

IUnitTestCallbackRegistration<TInterface>

The IUnitTestCallbackRegistration is a special IRegistrationBase that allows to set a ResolveCallback<TInterface> as a callback that is called on IIocContainer.Resolve<T>. This can be useful if you for whatever reason need some special handling for unit tests.

The ResolveCallback<TInterface> looks like this:

public delegate TInterface ResolveCallback<out TInterface>(params object[] parameters);