Using PubSubLite with an IOC container

Register typemappings

PubSubLite contains the typemappings needed to register and resolve the IBus interface in an IOC container.

Use the PubSubLite.IOC.PubSubLiteMappingsModule class to get the mappings needed by the bus and register them in the container of your choice.

The following code shows how the dependencies needed by the bus can be registred in your bootstrapping.

The IOC container must resolve the bus using the "greediest constructor".

Code example
using PubSubLite.IOC;

// get typemappings
var mappingsModule = new PubSubLiteMappingsModule();

foreach(var mapping in mappingsModule.Mappings)
{
      RegisterType(mapping.AbstractType, mapping.ImplementingType, mapping.Name);
}

private void RegisterType(Type abstractType, Type implementingType, string mappingName)
{
      // register type in your IOC container here
}

When this is done you should be able to resolve/inject the IBus interface in your application.

The demo project (downloads) contains an example using Castle Windsor.

Last edited Nov 11, 2010 at 12:47 AM by swmal, version 10

Comments

No comments yet.