parent
4ba827da61
commit
616a51c566
1 changed files with 61 additions and 1 deletions
@ -1 +1,61 @@ |
||||
The `RegistrationFactory` |
||||
The `RegistrationFactory` is a helper class to register interfaces and factories in an `IIocInstaller` and create the needed `IRegistrationBase`s. |
||||
|
||||
## 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>()`: |
||||
|
||||
```c# |
||||
RegistrationFactory.Register<IFoo, Foo>(); |
||||
``` |
||||
|
||||
If for whatever reason you can't use this method, there is also a non generic version of it: |
||||
|
||||
```c# |
||||
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>()`: |
||||
|
||||
```c# |
||||
RegistrationFactory.Register<IFoo, Foo>(Lifestyle.Singleton); |
||||
``` |
||||
|
||||
There is again the possibility to use a non generic version of the method: |
||||
|
||||
```c# |
||||
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>()`: |
||||
|
||||
```c# |
||||
RegistrationFactory.Register<IFoo, Foo, TScope>(); |
||||
``` |
||||
|
||||
Again there is a non generic method to use: |
||||
|
||||
```c# |
||||
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>()`: |
||||
|
||||
```c# |
||||
RegistrationFactory.RegisterFactory<IFooFactory>(container); |
||||
``` |
||||
|
||||
There is also a non generic version of the method available: |
||||
|
||||
```c# |
||||
RegistrationFactory.RegisterFactory(typeof(IFooFactory), container); |
||||
``` |
||||
|
||||
Loading…
Reference in new issue