- add first draft of iiocInstaller and FromAssembly

master
Simon Gockner 7 years ago
parent 9aa4d879ca
commit 6e2adc3ece
  1. 1
      FromAssembly.md
  2. 1
      Home.md
  3. 63
      IIocInstaller.md
  4. 1
      _Sidebar.md

@ -0,0 +1 @@
The `FromAssembly` class is a static helper class that supplies methods to find the wanted `Assembly` for an `IAssemblyInstaller`. Is acts similar to a factory in the way that its methods return a new instance of an `IAssemblyInstaller` with the assembly that they provide.

@ -18,6 +18,7 @@ Welcome to the Lightweight IOC Container wiki!
- [Use factories to resolve instances](Advanced-Usage-of-Lightweight-IOC-Container#Use-factories-to-resolve-instances) - [Use factories to resolve instances](Advanced-Usage-of-Lightweight-IOC-Container#Use-factories-to-resolve-instances)
- Detailed documentation - Detailed documentation
- [Abstract factories](Abstract-factories) - [Abstract factories](Abstract-factories)
- [`FromAssembly`](FromAssembly)
- [IIocInstaller](IIocInstaller) - [IIocInstaller](IIocInstaller)
- [Lifestyles](Lifestyles) - [Lifestyles](Lifestyles)
- [`RegistrationFactory`](RegistrationFactory) - [`RegistrationFactory`](RegistrationFactory)

@ -1 +1,64 @@
The `IIocInstaller` interface is the base class for all installers that are used by the `IocContainer`. The `IIocInstaller` interface is the base class for all installers that are used by the `IocContainer`.
## Base interface
The base interface only consists of one method, the `Install()` method:
```c#
void Install(IIocContainer container);
```
The `Install()` method installs the given `IRegistrationBase`s in the given `IIocContainer`.
To create your own installer, you have to implement the `IIocInstaller` interface and the `Install()` method. Inside the `Install()` method you have to register the `IRegistrationBase`s with the given `IIocContainer`:
```c#
container.Register(RegistrationFactory.Register<IFoo, Foo>());
```
The following is an example `IIocInstaller`:
```c#
public class Installer : IIocInstaller
{
public void Install(IIocContainer container)
{
container.Register(RegistrationFactory.Register<IFoo, Foo>());
}
}
```
## `AssemblyInstaller`
The `AssemblyInstaller` is an implementation of the `IIocInstaller`. It installs all `IIocInstaller`s for a given `Assembly`.
To do so, it checks each `Type` in the `Assembly` it is given if it is derived from `IIocInstaller`:
```c#
public AssemblyInstaller(Assembly assembly)
{
Installers = new List<IIocInstaller>();
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (!typeof(IIocInstaller).IsAssignableFrom(type))
continue;
Installers.Add((IIovInstaller) Activator.CreateInstance(type));;
}
}
```
This list of `IIocInstaller`s is then installed when the `AssemblyInstaller`s `Install()` method is called:
```c#
public void Install(IIocContainer container)
{
foreach (IIocInstaller installer in Installers)
{
installer.Install(container);
}
}
```
With the help of the [`FromAssembly`](FromAssembly) class, `AssemblyInstaller`s can be created and provided with their needed `Assembly`.

@ -16,6 +16,7 @@
- [Use factories to resolve instances](Advanced-Usage-of-Lightweight-IOC-Container#Use-factories-to-resolve-instances) - [Use factories to resolve instances](Advanced-Usage-of-Lightweight-IOC-Container#Use-factories-to-resolve-instances)
- Detailed documentation - Detailed documentation
- [Abstract factories](Abstract-factories) - [Abstract factories](Abstract-factories)
- [`FromAssembly`](FromAssembly)
- [IIocInstaller](IIocInstaller) - [IIocInstaller](IIocInstaller)
- [Lifestyles](Lifestyles) - [Lifestyles](Lifestyles)
- [`RegistrationFactory`](RegistrationFactory) - [`RegistrationFactory`](RegistrationFactory)

Loading…
Cancel
Save