- update simple usage guide

- add detailed documentation
master
Simon Gockner 7 years ago
parent 928c3517cb
commit ee52314066
  1. 2
      Home.md
  2. 1
      Lifestyles.md
  3. 34
      Simple-Usage-of-Lightweight-IOC-Container.md

@ -12,3 +12,5 @@ Welcome to the Lightweight IOC Container wiki!
- [[Install IIocInstallers|Simple-Usage-of-Lightweight-IOC-Container#Install-IIocInstallers]]
- [[Resolving instances|Simple-Usage-of-Lightweight-IOC-Container#Resolving-Instances]]
- [[Disposing Container|Simple-Usage-of-Lightweight-IOC-Container#Disposing-Container]]
- Detailed documentation
- [[Lifestyles|Lifestyles]]

@ -0,0 +1 @@
There are multiple Lifestyles available.

@ -2,8 +2,42 @@ This is a simple usage guide of the Lightweight IOC Container.
## Instantiate container
The easiest way to instantiate the `IocContainer` is to create an instance of it at the start of your application:
```c#
IocContainer container = new IocContainer();
```
## Install `IIocInstaller`s
To be able to resolve instances from the `IocContainer`, you need to register them first.
There are multiple ways to accomplish this and the best solution depends on the complexity of your project.
In this simple usage guide we will only take a look at the most straightforward way that is to just register the interfaces and their classes with the `IocContainer`:
```c#
container.Register(new DefaultRegistration<IInterface>(typeof(IInterface), typeof(Implementation), Lifestyle.Transient));
```
To make this even easier there is a `RegistrationFactory` that helps you create the `IRegistrationBase` you need:
```c#
container.Register(RegistrationFactory.Register<IInterface, Implementation>());
```
There are multiple [[lifestyles|Lifestyles]] available, make sure you choose the correct one for your need.
## Resolving instances
To resolve an instance with the `IocContainer`, do the following:
```c#
IInterface interface = container.Resolve<IInterface>();
```
## Disposing Container
When your application is finished make sure to dispose your `IocContainer`:
```c#
container.Dispose();
```

Loading…
Cancel
Save