diff --git a/Advanced-Usage-of-Lightweight-IOC-Container.md b/Advanced-Usage-of-Lightweight-IOC-Container.md index 35022b8..ccde47e 100644 --- a/Advanced-Usage-of-Lightweight-IOC-Container.md +++ b/Advanced-Usage-of-Lightweight-IOC-Container.md @@ -29,7 +29,7 @@ public class Installer : IIocInstaller { public void Install(IIocContainer container) { - container.Register(RegistrationFactory.Register()); + container.Register(); } } ``` diff --git a/IIocInstaller.md b/IIocInstaller.md index 7607ca1..4ef4679 100644 --- a/IIocInstaller.md +++ b/IIocInstaller.md @@ -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()); +container.Register(); ``` The following is an example `IIocInstaller`: @@ -23,7 +23,7 @@ public class Installer : IIocInstaller { public void Install(IIocContainer container) { - container.Register(RegistrationFactory.Register()); + container.Register(); } } ``` diff --git a/IRegistrationBase.md b/IRegistrationBase.md index e34c432..2ebeda4 100644 --- a/IRegistrationBase.md +++ b/IRegistrationBase.md @@ -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` + +The `IUnitTestCallbackRegistration` is a special `IRegistrationBase` that allows to set a `ResolveCallback` as a callback that is called on `IIocContainer.Resolve`. This can be useful if you for whatever reason need some special handling for unit tests. + +The `ResolveCallback` looks like this: + +```c# +public delegate TInterface ResolveCallback(params object[] parameters); +``` diff --git a/Lifestyles.md b/Lifestyles.md index 33b2a62..be2624d 100644 --- a/Lifestyles.md +++ b/Lifestyles.md @@ -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()); +container.Register()); ``` ## `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(Lifestyle.Singleton)); +container.Register(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()); +container.Register(); ``` diff --git a/RegistrationFactory.md b/RegistrationFactory.md index 198ed1f..621bb3e 100644 --- a/RegistrationFactory.md +++ b/RegistrationFactory.md @@ -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). diff --git a/Simple-Usage-of-Lightweight-IOC-Container.md b/Simple-Usage-of-Lightweight-IOC-Container.md index ae64fa0..8d10662 100644 --- a/Simple-Usage-of-Lightweight-IOC-Container.md +++ b/Simple-Usage-of-Lightweight-IOC-Container.md @@ -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(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()); +container.Register(); ``` There are multiple [lifestyles](Lifestyles) available, make sure you choose the correct one for your need.