- update usage for v1.3.0

master
Simon Gockner 6 years ago
parent db96c6f6c2
commit e4d7e536ba
  1. 2
      Advanced-Usage-of-Lightweight-IOC-Container.md
  2. 4
      IIocInstaller.md
  3. 10
      IRegistrationBase.md
  4. 8
      Lifestyles.md
  5. 2
      RegistrationFactory.md
  6. 8
      Simple-Usage-of-Lightweight-IOC-Container.md

@ -29,7 +29,7 @@ public class Installer : IIocInstaller
{
public void Install(IIocContainer container)
{
container.Register(RegistrationFactory.Register<IFoo, Foo>());
container.Register<IFoo, Foo>();
}
}
```

@ -13,7 +13,7 @@ The `Install()` method installs the given [`IRegistrationBase`s](IRegistrationBa
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](IRegistrationBase) with the given `IIocContainer`:
```c#
container.Register(RegistrationFactory.Register<IFoo, Foo>());
container.Register<IFoo, Foo>();
```
The following is an example `IIocInstaller`:
@ -23,7 +23,7 @@ public class Installer : IIocInstaller
{
public void Install(IIocContainer container)
{
container.Register(RegistrationFactory.Register<IFoo, Foo>());
container.Register<IFoo, Foo>();
}
}
```

@ -80,3 +80,13 @@ private void CreateFactory(IIocContainer container)
```
This is done by writing the IL code for the `Create()` methods manually that call the `IocContainer.Resolve()` method, as well as the `ClearMultitonInstance` method that calls the `IocContainer.ClearMultitonInstances<>()` method.
## `IUnitTestCallbackRegistration<TInterface>`
The `IUnitTestCallbackRegistration` is a special `IRegistrationBase` that allows to set a `ResolveCallback<TInterface>` as a callback that is called on `IIocContainer.Resolve<T>`. This can be useful if you for whatever reason need some special handling for unit tests.
The `ResolveCallback<TInterface>` looks like this:
```c#
public delegate TInterface ResolveCallback<out TInterface>(params object[] parameters);
```

@ -8,12 +8,12 @@ The lifestyles are part of the enum `Lifestyle`.
Using the `Transient`-Lifestyle, a new instance gets created every time an instance is resolved.
`Transient` instances are not tracked by the `IocContainer`, so once you don't need them anymore they can be claimed by the garbage collector without leaking memory.
:information_source: This is the default `Lifestyle` that the [`RegistrationFactory`](RegistrationFactory) uses.
:information_source: This is the default `Lifestyle` that the `IocContainer` uses.
This is how you register a class as `Transient`:
```c#
container.Register(RegistrationFactory.Register<IFoo, Foo>());
container.Register<IFoo, Foo>());
```
## `Lifestyle.Singleton`
@ -25,7 +25,7 @@ This is specifically useful if you have a service that needs to be accessed by m
This is how you register a class as `Singleton`:
```c#
container.Register(RegistrationFactory.Register<IFoo, Foo>(Lifestyle.Singleton));
container.Register<IFoo, Foo>(Lifestyle.Singleton);
```
## `Lifestyle.Multiton`
@ -43,5 +43,5 @@ They will also be released once the `IocContainer` is disposed.
This is how you register a class as `Multiton`:
```c#
container.Register(RegistrationFactory.Register<IFoo, Foo, TScope>());
container.Register<IFoo, Foo, TScope>();
```

@ -1,5 +1,7 @@
The `RegistrationFactory` is a helper class to register interfaces and factories in an [`IIocInstaller`](IIocInstaller) and create the needed [`IRegistrationBase`s](IRegistrationBase).
> The `RegistrationFactory` is private helper class. These methods will be used when you call `IIocContainer.Register<>()`.
## Registering classes
The way classes are registered depends on their [`Lifestyle`](Lifestyles).

@ -15,13 +15,7 @@ There are multiple ways to accomplish this and the best solution depends on the
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(IFoo), typeof(Foo), Lifestyle.Transient));
```
To make this even easier there is a [`RegistrationFactory`](RegistrationFactory) that helps you create the [`IRegistrationBase`](IRegistrationBase) you need:
```c#
container.Register(RegistrationFactory.Register<IFoo, Foo>());
container.Register<IFoo, Foo>();
```
There are multiple [lifestyles](Lifestyles) available, make sure you choose the correct one for your need.

Loading…
Cancel
Save