This project is read-only.

SSB and Windsor Castle integration

Jun 24, 2009 at 1:14 AM
Edited Jun 24, 2009 at 11:04 PM

Hello,
Is there sample or description how SSB could be integrated with Windsor Castle dependency injection container. 
What would be an approach to use IoC at full extend?

Should I define my own SimpleServiceBus.Utilities.ObjectBuilder.IObjectBuilder to wrap IoC?

Thanks

Jun 25, 2009 at 11:56 PM

Seems like that was only what I should do.

Jun 26, 2009 at 1:06 AM

Sorry for the delayed response - yes, that is all you should need to do - it is a pretty simply interface, so I don't think you will have any problem.

Jun 26, 2009 at 7:21 PM
Edited Jun 26, 2009 at 8:09 PM

Do I have to register SSB components with IoC myself or there is a way SSB will take care of it? At this point I did it like code below. If this way is correct (which I doubt) how then I should define lifestyle for all these compoenents?


Container.Register(Component.For<IMessagingEndpoint>().ImplementedBy<MessagingEndpoint>().Named("ssbMessagingEndpoint"));
Container.Register(
Component.For<IMessageSerializer>().ImplementedBy<XmlMessageSerializer>().Named("ssbMessageSerializer"));
Container.Register(
Component.For<IMessageBus>().ImplementedBy<MessageBus>().Named("ssbMessageBus"));
Container.Register(
Component.For<ITransport>().ImplementedBy<MsmqTransport>().Named("ssbTransport"));
Container.Register(
Component.For<IMessageIdGenerator>().ImplementedBy<DefaultMessageIdGenerator>().Named("ssbMessageIdGenerator"));
Container.Register(
Component.For<IMessagePipelineFactory>().ImplementedBy<DefaultMessagePipelineFactory>().Named("ssbMessagePipelineFactory"));
Container.Register(
Component.For<IMessageHandlerResolutionService>().ImplementedBy<DefaultMessageHandlerResolutionService>().Named("ssbDefaultMessageHandlerResolutionService"));
Container.Register(Component.For<IMessageDispatcher>().ImplementedBy<DefaultMessageDispatcher>().Named("ssbDefaultMessageDispatcher"));
Container.Register(
Component.For<ICorrelatedCallbackManager>().ImplementedBy<DefaultCallbackManager>().Named("ssbDefaultCallbackManager"));
Container.Register(
Component.For<IMessageTypeManagementService>().ImplementedBy<DefaultMessageTypeManagementService>().Named("ssbDefaultMessageTypeManagementService"));
Container.Register(
Component.For<ISubscriptionRepository>().ImplementedBy<NullSubscriptionRepository>().Named("ssbNullSubscriptionRepository"));
Container.Register(
Component.For<ISubscriptionManager>().ImplementedBy<DefaultSubscriptionManager>().Named("ssbDefaultSubscriptionManager"));
Container.Register(
Component.For<IMessagePipeline>().ImplementedBy<MessagePipeline>().Named("ssbMessagePipeline"));
Container.Register(
Component.For<IMessageLogger>().ImplementedBy<DefaultMessageLogger>().Named("ssbDefaultMessageLogger"));
Container.Register(
Component.For<MessageExpressionEvaluator>().Named("ssbMessageExpressionEvaluator"));
Container.Register(
Component.For<MessageFilterService>().Named("ssbMessageFilterService"));

Jul 16, 2009 at 1:04 AM

If you want to define the lifestyle of one of your components, I believe you need to do it the way you demonstrated. However, SSB should use your IObjectBuilder to register framework components automatically if they aren't already registered by you, so unless you want to change the default lifestyle of one of these components, you should only need to register exceptions.

Jul 16, 2009 at 2:52 AM

It is still not clear for me how should I use IObjectBuilder interface to register SSB components. According to DefaultObjectBuilderService method my ObjectBuilder implementation should check if interface of ServiceType has been registred with a container and return NULL it it has not. It should do it with TryBuild(). If Interface is not registred then register it's default implementation and resolve it via ObjectBuilder.Build()


I do not see how can I register a pair IServiceType/DefaultImplementation without preregistring it myself. Currently I am getting unresolved IMessageBus exception when SSB asks ioc to resolve DefaultSubscriptionManager, because my ioc collected information about MessageBus implementation only.

public ServiceType BuildService<ServiceType, DefaultImplementation>()
            where ServiceType : class
            where DefaultImplementation : class, ServiceType
        {
            var tryIoC = ObjectBuilder.TryBuild<ServiceType>();
            if (tryIoC == null)
                return ObjectBuilder.Build<DefaultImplementation>();
            return tryIoC;
        }
Please let me know what is wrong here.

Thanks a lot for your help!

Jul 17, 2009 at 1:20 AM

Let me add to this thread, so for example in Castle Windsor when you register a component (service) you need to tell it that class Xyz implements interface IXyz in the same method. In the IObjectBuilder you have two different methods, one that tests the interface and if it fails then it builds the implementation. I believe that works in StructureMap since it has some auto-build capabilities, but in Castle we have to tell it which interface an implementation should be registered as.

/Hakan