10 RegistrationFactory
Simon Gockner edited this page 6 years ago

The RegistrationFactory is a helper class to register interfaces and factories in an IIocInstaller and create the needed IRegistrationBases.

The RegistrationFactory is a private helper class. These methods will be used when you call IIocContainer.Register<>().

Registering classes

The way classes are registered depends on their Lifestyle.

Register Transient classes

To register Transient classes, an IDefaultRegistration<TInterface> has to be created. The preferred way to do so is to use the generic method Register<TInterface, TImplementation>():

RegistrationFactory.Register<IFoo, Foo>();

If for whatever reason you can't use this method, there is also a non generic version of it:

RegistrationFactory.Register(typeof(IFoo), typeof(Foo));

Register Singleton classes

To register Singleton classes, there has to be a IDefaultRegistration<TInterface> created as well. Similar to the registration of Transient classes, the preferred way to register Singleton classes is to use the generic method Register<TInterface, TImplementation>():

RegistrationFactory.Register<IFoo, Foo>(Lifestyle.Singleton);

There is again the possibility to use a non generic version of the method:

RegistrationFactory.Register(typeof(IFoo), typeof(Foo), Lifestyle.Singleton);

Register Multiton classes

To register Multiton classes, an IMultitonRegistration<TInterface> has to be created. The preferred way to do so is to use the generic method Register<TInterface, TImplementation, TScope>():

RegistrationFactory.Register<IFoo, Foo, TScope>();

Again there is a non generic method to use:

RegistrationFactory.Register(typeof(IFoo), typeof(Foo), typeof(TScope));

Registering factories

To register abstract factories, an ITypedFactoryRegistration<TFactory> has to be created. The preferred way to do so is to use the generic method RegisterFactory<TFactory>():

RegistrationFactory.RegisterFactory<IFooFactory>(container);

There is also a non generic version of the method available:

RegistrationFactory.RegisterFactory(typeof(IFooFactory), container);