Skip to content
MagicIOC is a zero-configuration IOC container for .NET
C#
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
MagicIOC.Tests
MagicIOC
packages
License.txt
MagicIOC.sln
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.