Getting Started

In order to get started with Agnostic IoC follow these simple steps.

Plugin code
In your plugin assemblies, simply download the Agnostic.IoC.Core nuget package.

Consumer code
In your consuming assemblies, you will simply need to download the Agnostic.IoC.YourContainerOfChoice nuget package, if your container isn’t currently supported, please comment and we will endeavor to help you make it so.

Container Manager

In your consuming code, you can access the containers at any time by using the ContainerManager class, this accepts several constructor arguments. The ContainerManager can maintain references to multiple ContainerAdapter instances utilising a string key to switch between them.

The default constructor utilises String.Empty as the key and attempts to scan your loaded assemblies for a class inheriting from IContainerAdapter with the Name property of String.Empty (the default for container adapters).

IContainerManager containerManager = new ContainerManager();

You may also instantiate a ContainerManager with a known container type:

            // register an autofac container adapter.
            var adapter = new AutofacContainerAdapter("MyContainer");
            adapter.Register<IDependantClass, DependantClass2>();
            IContainerManager containerManager = new ContainerManager(adapter);

            // now my container adapter is known, I can refer to it in future using the string key
            var containerManager2 = new ContainerManager("MyContainer");

ContainerAdapter classes generally support a dependency injected container, so it allows pre-existing containers to be used.

            // Register components with the original container
            IWindsorContainer container = new WindsorContainer();
            // it isn't necessary to use a container key, but this shows you can.
            ContainerManager containerManager = new ContainerManager(new WindsorContainerAdapter("MyContainer", container));
            IDependantClass dependency = containerManager.Resolve<IDependantClass>();
            Assert.AreEqual(typeof(DependantClass), dependency.GetType());

Individual Registrations

Individual registrations can be made against Agnostic IoC containers by calling:

IContainerManager containerManager = new ContainerManager(new AutofacContainerAdapter());
containerManager.Adapter.Register<IDependantClass, DependantClass>();

Group Registrations

Group Registrations can be contained within your plugin codebase by creating a class deriving from IContainerManagerGroupRegisration (see the example below).

    public class TestGroupRegistration : IContainerManagerGroupRegistration
        public void RegisterComponents(IContainerAdapter containerAdapter)
            containerAdapter.Register<IDependantClass, DependantClass>();
            containerAdapter.Register<IDependantClass, DependantClass2>("new name");

You may register this with the container manager by calling:


Resolving components can be performed from the ContainerManager or ContainerAdapter objects using the ‘Resolve’ methods.

One thought on “Getting Started

  1. Pingback: Agnostic IoC – Released | CardinalCore

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s