Fluent Registration API

Overview

Here is a general look at the fluent registration in action. This is a simple registration of a component by a single interface.

            IContainerManager containerManager = new ContainerManager(); // this will often be elsewhere

            var registration = containerManager.Adapter.CreateComponentRegistration<ComponentRegistration>()
                .Register<ISuperDependantClass>()
                .As<DependantClass>();

            adapter.Register(registration);

Registering a component as multiple types

The fluent registration api allows the easy registration of components against multiple interfaces.

            var registration = containerManager.Adapter.CreateComponentRegistration<ComponentRegistration>()
                .Register<IDependantClass, ISuperDependantClass>()
                .As<DependantClass>();

Named

Named registrations can be achieved simply by using the ‘Named’ method. This accepts the string of the registration name.

            var registration = containerManager.Adapter.CreateComponentRegistration<ComponentRegistration>()
                .Register<ISuperDependantClass>()
                .As<DependantClass>()
                .Named("name");

Instance Registrations

Instance Registrations can be achieved simply by using the Instance() method. This accepts the instance of the object that you wish to return.

            IContainerAdapter adapter = adapterFunc();

            var returnClass = new DependantClass();

            var registration = adapter.CreateComponentRegistration<ComponentRegistration>()
                .Register<ISuperDependantClass>()
                .Instance(returnClass);

            adapter.Register(registration);
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s