Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

MagicIOC is a zero-configuration IOC container for .NET

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 MagicIOC.Tests
Octocat-spinner-32 MagicIOC
Octocat-spinner-32 packages
Octocat-spinner-32 License.txt
Octocat-spinner-32 MagicIOC.sln
Octocat-spinner-32 README
README
MagicIOC is a simple, zero-configuration IOC container for .NET.
---------------------------------------------------------------

It is based on the concept that interfaces are often created for the purposes of testability and loose coupling, as opposed to the ability to have multiple implementations. By using this assumption, MagicIOC allows for interface and class resolving with no configuration at all.

Here are a few examples of its usage. Note the lack of setup/configuration!

Resolving a class:
var myClass = MagicIOC.Get<MyClass>();

Resolving an interface:
var myInterfaceImpl = MagicIOC.Get<IMyInterface>();


Creating new objects instead of always returning cached ones:
var impl1 = MagicIOC.Get<IMyInterface>(CachePolicy.New);
var impl2 = MagicIOC.Get<IMyInterface>(CachePolicy.New);
// impl1 != impl2


That's all there is to it!
Now consider a more complicated class hierarchy:

public interface ICustomerRepository
{
}

public class CustomerRepository : ICustomerRepository
{
}

public interface IOrderRepository
{
}

public class OrderRepository : IOrderRepository
{
}

public interface IOrderProcessor
{
}

public class OrderProcessor : IOrderProcessor
{
    public OrderProcessor(ICustomerRepository customerRepository, IOrderRepository orderRepository)
    {
    }
}


var orderProcessor = MagicIOC.Get<IOrderProcessor>();

MagicIOC automatically finds the OrderProcessor implementation of the IOrderProcessor interface. It then discovers the ICustomerRepository and IOrderRepository dependencies, creates their implementations, and passes them to the OrderProcessor constructor.

Something went wrong with that request. Please try again.