diff --git a/FromAssembly.md b/FromAssembly.md new file mode 100644 index 0000000..471f7e8 --- /dev/null +++ b/FromAssembly.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. diff --git a/Home.md b/Home.md index a4353f2..b050d81 100644 --- a/Home.md +++ b/Home.md @@ -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) - Detailed documentation - [Abstract factories](Abstract-factories) + - [`FromAssembly`](FromAssembly) - [IIocInstaller](IIocInstaller) - [Lifestyles](Lifestyles) - [`RegistrationFactory`](RegistrationFactory) diff --git a/IIocInstaller.md b/IIocInstaller.md index f8c5ae8..e52095c 100644 --- a/IIocInstaller.md +++ b/IIocInstaller.md @@ -1 +1,64 @@ 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()); +``` + +The following is an example `IIocInstaller`: + +```c# +public class Installer : IIocInstaller +{ + public void Install(IIocContainer container) + { + container.Register(RegistrationFactory.Register()); + } +} +``` + +## `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(); + + 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`. diff --git a/_Sidebar.md b/_Sidebar.md index 6c086d5..6ed5e22 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -16,6 +16,7 @@ - [Use factories to resolve instances](Advanced-Usage-of-Lightweight-IOC-Container#Use-factories-to-resolve-instances) - Detailed documentation - [Abstract factories](Abstract-factories) + - [`FromAssembly`](FromAssembly) - [IIocInstaller](IIocInstaller) - [Lifestyles](Lifestyles) - [`RegistrationFactory`](RegistrationFactory)