DevTeam / IoC

Inversion of Control container for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple, powerful and fast Inversion of Control container for .NET

There are many different implementations of Inversion of Control. Why it would be preferable to use this implementation? It has many outstanding features to make your code more efficient. See Wiki for details.

Supported platforms:

  • .NET 3.5+
  • .NET Core 1.0+
  • .NET Standard 1.0+

Comparison test Comparison test of some IoC containers in the synthetic test (creating a graph from 2 transient and singleton objects in the serie of 100k iterations) has the following result.

Shroedingers Cat shows how it works:

using (var container = new Container().Configure().DependsOn<Glue>().ToSelf())
{
    var box = container.Resolve().Instance<IBox<ICat>>();
    Console.WriteLine(box.Content.IsAlive);
}

Abstraction:

interface IBox<T> { T Content { get; } }

interface ICat { bool IsAlive { get; } }

Implementation:

Cat

class CardboardBox<T> : IBox<T>
{
    public CardboardBox(T content) { Content = content; }

    public T Content { get; }
}

class ShroedingersCat : ICat
{
    public bool IsAlive => true; // for humanistic reasons
}

Let's glue it together:

class Glue: IConfiguration
{
    public IEnumerable<IConfiguration> GetDependencies(IContainer container)
    {
        yield break;
    }

    public IEnumerable<IDisposable> Apply(IContainer container)
    {
        yield return container.Register()
            .Autowiring(typeof(IBox<>), typeof(CardboardBox<>))
            .And().Autowiring<ICat, ShroedingersCat>();
    }
}

And the another way is to glue via Json file:

[
  { "reference": "ConsoleApp" },
  { "using": "ConsoleApp" },

  { "class": "CardboardBox<> : IBox<>" },
  { "class": "ShroedingersCat : ICat" }
]

About

Inversion of Control container for .NET

License:GNU General Public License v3.0


Languages

Language:C# 100.0%Language:Batchfile 0.0%