Clone wiki

DryIoc / Home

Wiki Home

Getting Started

Starting from simple interface/implementation setup:

    public interface IService { }
    public class SomeService : IService { }

    public interface IClient { IService Service { get; } }
    public class SomeClient : IClient
    {
        public IService Service { get; private set; }
        public SomeClient(IService service) { Service = service; }
    }

Let's compare creation of SomeClient manually and with DryIoc.

How to instantiate SomeClient with DI principle in mind:

    IClient client = new SomeClient(new SomeService());

That's hard-wired!

How to do that with DryIoc:

    var c = new Container();
    c.Register<IClient, SomeClient>();
    c.Register<IService, SomeService>();

    // somewhere else
    IClient client = c.Resolve<IClient>();

In DryIoc we are declaring/registering mapping between interfaces and implementations. Then in different space and time we are deciding to get/resolve IClient object with its dependencies by providing only client interface.

Hey, it means that I can register different IClient implementations without touching consumer resolution code. And we are not speaking about good singletons yet.

So IoC container helps me to enforce Open-Closed principle and to improve Testability and Extensibility of my software.

Usage Guide

Companions

Extensions

Samples

Located in this repo:

External links:

Latest Version

Get from NuGet:

  • DryIoc.dll NuGet Badge
  • DryIoc (source code) NuGet Badge
  • DryIoc.Internal (source code with public types made internal) NuGet Badge

v3.0.0 / 2018-06-24

Release Notes

Previous Versions

Updated