Registration providers

Registration providers are .Net classes, which are automatically picked up and used, by the Lambda Container (LC) bootstrapper.

The purpose of a registration provider is to provide type and/or lambda factory registrations for the types published by the assembly/component.

Lambda Container provides 3 different ways of defining how a type should be built:

1: By lambda factory method

Using the interface IFactoryProvider, you can register factory methods to construct the types.
As a first argument, the calling LC is passed, so that any constructor arguments may be resolved, if needed, through that. You can use the factory provider to either map an interface to an implementation factory or determine how an implementing class should be instantiated.

public class Provider1 : IFactoryProvider
    {
        public void ProvideRegistrationsTo(IFactoryConsumer target)
        {
            target.Register<IAclass>(lc=>new AClass(lc.GetInstance<IAchild>()));
        }
    }

2: By F# lambda factory method

Using the interface IFactoryFSharpConsumer, you can register factory methods to construct the types.
As a first argument, the calling LC is passed, so that any constructor dependencies may be resolved through that. You can use the factory provider to either map an interface to an implementation factory or determine how an implementing class should be instantiated.

type public Provider1() =
    interface IFactoryFSharpProvider with
        member this.ProvideRegistrationsTo target =
            target.Register<string> (fun container -> "a registered string")

3: By Type

If you want LC to take care of all of the type buildup, use the ITypeRegistrationsProvider interface.

Types are registered as "from-to" pairs meaning: GetInstance<from> will return an instance of <to>. This also means that the type <from> can be registered as <to> and in another provider a factory method for <to> can be registered.

If a factory method for <to> is not registered, LC will attempt to build up the <to> type by selecting the constructor that:
  • Is public and marked with the LambdaContainerInjectionConstructor attribute
  • Is public and has the largest amount of arguments.
If the selected constructor has any arguments, these are injected through LC as well.

public class Provider3 : ITypeRegistrationsProvider
    {
        public void ProvideRegistrationsTo(ITypeRegistrationsConsumer target)
        {
            target.RegisterType<IAchild, AChild>();
            target.RegisterType<IAclass, AClass>();
            target.RegisterTypeAsApplicationSingleton<IAchild2, AChild>();
        }
    }

Last edited Aug 6, 2015 at 7:50 PM by Remboel, version 7