Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

DevTeam/IoC

Repository files navigation

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" }
]

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /