Skip to content

Dependency Injection DryIoC

Daniel edited this page Aug 16, 2020 · 15 revisions

CodeMonkeys.DependencyInjection.Ninject

Nuget

The CodeMonkeys.DependencyInjection.Ninject package is our framework abstraction for the widely known DryIoc container.

How to work with it?

Using the abstraction is easy. You just need to call the factory method CreateInstance to get a container instance. Like this:

// Will return a instance which uses DryIoc internally
var container = DryFactory.CreateInstance();

// Will return a instance which uses DryIoc internally and writes log messages with the given logger
var logger = LogServiceFactory.Instance.Create(nameof(Program));
var container2 = DryFactory.CreateInstance(logger );

Important: By default, we disable the use of System.Reflection.Emit because on iOS it will not work. The linker is striping the entire namespace which will otherwise lead to problems.

You can control this behavior with a optional parameter:

CreateInstance(
    bool allowReflectionEmit = false)

CreateInstance(
    ILogService logService, 
    bool allowReflectionEmit = false)

Clone this wiki locally