Table of Contents

Dependency Injection

WhiteLabel declares its abstraction over the DI implementation.

DryIoc is used out of the box.

Registration

To register dependencies you should use IContainerBuilder.

Sample:

containerBuilder.Singleton<JsonSerializer, IJsonSerializer>();

When you register new instances of internal services, you need to use IfRegistered.Replace otherwise you will have runtime exception about duplication registration.

Resolving

To resolving registered dependencies you should use IContainer.

Sample:

container.Resolve<IJsonSerializer>();

Lazy

Because WhiteLabel use DryIoc under the hood, our IContainer has the implicit ability for lazy, factory resolving (DryIoc doc, Autofac doc)

container.Resolve<Lazy<IJsonSerializer>>();

ViewModel

All ViewModels that registered and used with WhiteLabel can resolve dependency via the constructor.

public class MyViewModel : ViewModelBase
{
    public MyViewModel(
        Lazy<IJsonSerializer> serializer,
        IDataService dataService)
    {
    }
}