From ee523140667683ca2912c548a4a18494d67a0ebf Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Thu, 4 Jul 2019 17:16:05 +0200 Subject: [PATCH] - update simple usage guide - add detailed documentation --- Home.md | 2 ++ Lifestyles.md | 1 + Simple-Usage-of-Lightweight-IOC-Container.md | 34 ++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 Lifestyles.md diff --git a/Home.md b/Home.md index 98ed42c..d90d7c6 100644 --- a/Home.md +++ b/Home.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]] diff --git a/Lifestyles.md b/Lifestyles.md new file mode 100644 index 0000000..e8fb860 --- /dev/null +++ b/Lifestyles.md @@ -0,0 +1 @@ +There are multiple Lifestyles available. diff --git a/Simple-Usage-of-Lightweight-IOC-Container.md b/Simple-Usage-of-Lightweight-IOC-Container.md index cd53a2b..22f1d41 100644 --- a/Simple-Usage-of-Lightweight-IOC-Container.md +++ b/Simple-Usage-of-Lightweight-IOC-Container.md @@ -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(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()); +``` + +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(); +``` + ## Disposing Container + +When your application is finished make sure to dispose your `IocContainer`: + +```c# +container.Dispose(); +```