parent
4a693f08d1
commit
05707297ac
4 changed files with 61 additions and 0 deletions
@ -0,0 +1,44 @@ |
||||
Abstract factories are interfaces, that are implemented by the `LightweightIocContainer`. Using these factories is the recommended way to resolve any instances from the `IocContainer`. |
||||
|
||||
```c# |
||||
public interface IFooFactory |
||||
{ |
||||
// This is the main structure of every abstract factory |
||||
} |
||||
``` |
||||
|
||||
## `Create()` methods |
||||
|
||||
Every abstract factory has to have a `Create()` method with the return value you want to resolve: |
||||
|
||||
```c# |
||||
IFoo Create(); |
||||
``` |
||||
|
||||
If the constructor of the type you want to resolve has any arguments that can't be resolved by the `IocContainer`, you'll have to pass them as arguments to your `Create()` method: |
||||
|
||||
```c# |
||||
IFoo Create(string name); |
||||
``` |
||||
|
||||
Internally the `Create()` methods call `IocContainer.Resolve<>()`: |
||||
|
||||
```c# |
||||
IFoo foo = container.Resolve<IFoo>(name); |
||||
``` |
||||
|
||||
## `ClearMultitonInstance<>()` methods |
||||
|
||||
There is the possibility to add a method to the abstract factory that allows to clear `Multiton` instances. This method has to be a generic method to specify the type that is registered as a `Multiton` and whose instances should be deleted: |
||||
|
||||
```c# |
||||
void ClearMultitonInstance<IBar>(); |
||||
``` |
||||
|
||||
This method for example would clear all created `Multiton` instances of type `IBar`. |
||||
|
||||
Internally the `ClearMultitonInstance<>()` methods call `IocContainer.ClearMultitonInstances<>()`: |
||||
|
||||
```c# |
||||
container.ClearMultitonInstances<IBar>(); |
||||
``` |
||||
Loading…
Reference in new issue