RSB + ASP.NET MVC

102 views
Skip to first unread message

juan agui

unread,
Sep 21, 2011, 6:24:58 PM9/21/11
to Rhino Tools Dev
Hi guys,

I wonder if someone would share some code/pointers for registering RSB
with Castle.Windsor in an asp.net MVC web . Bottom line is having my
controllers injected with the bus dependency

NB: I tried using the Alexandria sample stuff, but its
Rhino.ServiceBus looks somewhat outdated.

Thanks,
Juan

Corey Kaylor

unread,
Sep 21, 2011, 7:27:16 PM9/21/11
to rhino-t...@googlegroups.com
Assuming you already use Windsor and have some bootstrapping code to wire things up. The configuration code should be very similar to what you find in most of the unit tests. Here's an example.

https://github.com/hibernating-rhinos/rhino-esb/blob/master/Rhino.ServiceBus.Tests/BusSubscriptionTests.cs#L20


--
You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" group.
To post to this group, send email to rhino-t...@googlegroups.com.
To unsubscribe from this group, send email to rhino-tools-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhino-tools-dev?hl=en.


Juan Agüí

unread,
Sep 22, 2011, 6:21:14 PM9/22/11
to rhino-t...@googlegroups.com
Hi Corey,

this is what I have:

in global.asax
 private readonly IWindsorContainer _container;

        public MvcApplication()
        {
            _container = new WindsorContainer(new XmlInterpreter());
            new RhinoServiceBusConfiguration().UseCastleWindsor();
            _container.Install(new MyWindsorInstaller());
        }

in MyWindsorInstaller
        public void Install(Castle.Windsor.IWindsorContainer
container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore
store)
        {
            container.Register(Component
               .For<HomeController>().LifeStyle.PerWebRequest.ImplementedBy<HomeController>());
        }
in HomeController
public HomeController(IServiceBus bus)

Unfortunately I'm getting the following exception:

Can't create component 'ElCarteroWebRole.Controllers.HomeController'
as it has dependencies to be satisfied.
ElCarteroWebRole.Controllers.HomeController is waiting for the
following dependencies:

Services:
- Rhino.ServiceBus.IServiceBus which was not registered.

Hence it looks like I'm failing to register the bus to IServiceBus in
Windsor. I thought RhinoServiceBusConfiguration will handle this, but
I'm obviously wrong. What am I missing?

Thanks!

Corey Kaylor

unread,
Sep 22, 2011, 6:53:26 PM9/22/11
to rhino-t...@googlegroups.com
new RhinoServiceBusConfiguration().UseCastleWindsor(_container).Configure();

Juan Agüí

unread,
Sep 23, 2011, 4:14:35 AM9/23/11
to rhino-t...@googlegroups.com
Still the same error. Maybe I'm missing something in my web.config?

<configuration>
<configSections>
<section name="castle"
type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
Castle.Windsor" />
<section name="rhino.esb"
type="Rhino.ServiceBus.Config.BusConfigurationSection,
Rhino.ServiceBus"/>
</configSections>
<rhino.esb>
<bus threadCount="1"
numberOfRetries="5"
endpoint="rhino.queues://localhost/test_queue"
queueIsolationLevel="ReadCommitted"
name="mybus"
/>
<messages>
<add name="Rhino.ServiceBus.Tests"
endpoint="msmq://localhost/test_queue"/>
<add name="Rhino.ServiceBus.Tests"
endpoint="msmq://localhost/test_queue2"/>
</messages>
</rhino.esb>
<castle/>

Thanks!

Matt Burton

unread,
Sep 23, 2011, 10:37:37 AM9/23/11
to rhino-t...@googlegroups.com
Are you overriding the default controller factory (or dependency
resolver in MVC 3) in your application and using a Castle-specific
one? If so you need to share the same container instance that you're
building with that, then your controller dependencies will be
satisfied.

Juan Agüí

unread,
Sep 26, 2011, 4:43:35 AM9/26/11
to rhino-t...@googlegroups.com
Hi Matt,

yes, in my global.asax

protected void Application_Start()
{
--> ControllerBuilder.Current.SetControllerFactory(new
WindsorControllerFactory(_container));


I was expecting that this line new
RhinoServiceBusConfiguration().UseCastleWindsor(_container).Configure();
would register IServiceBus in the container but it looks like I'm
missing something. My controllerfactory knows how to resolve
HomeController, but it
can't resolve IServiceBus

Thanks,
Juan

Corey Kaylor

unread,
Sep 26, 2011, 10:34:54 AM9/26/11
to rhino-t...@googlegroups.com
In the line right after you call .Configure can you resolve the IServiceBus there?

Juan Agüí

unread,
Sep 27, 2011, 7:55:18 AM9/27/11
to rhino-t...@googlegroups.com
Not really:

var bus = _container.Resolve<IServiceBus>(); yields a
[ComponentNotFoundException: No component for supporting the service
Rhino.ServiceBus.IServiceBus was found]

Matt Burton

unread,
Sep 27, 2011, 10:31:52 AM9/27/11
to rhino-t...@googlegroups.com
Juan -

From the bits we've seen it seems like you have all the required
pieces, but something is amiss if you can't resolve the bus as Corey
suggested. Would you mind posting your Global.asax code? (you could
make it available as a Gist on GitHub or use a service like pastie.org
to link to it and then take it down later) Perhaps by seeing it we'll
be able to help you diagnose the issue better.

Thanks,
Matt

Jason Meckley

unread,
Sep 27, 2011, 10:40:55 AM9/27/11
to rhino-t...@googlegroups.com
@jaun
it looks like you are creating/configuring the container & service bus in the ctor, not Application_Start. move this code to application start prior to setting the controller factory.

the global object is not a singleton. a new instance is created for each request. Application_Start (and Application_End) are unique methods, they are called exactly one time during the scope of the entire application. There are other unique methods Application_Error, Session_Start, Session_End, Application_BeginRequest, Application_EndRequest. they are automagically wired into the pipeline based on the naming conventions.

Juan Agüí

unread,
Oct 4, 2011, 5:47:02 PM10/4/11
to rhino-t...@googlegroups.com
Moving this code

_container = new WindsorContainer(new XmlInterpreter());
new

RhinoServiceBusConfiguration().UseCastleWindsor(_container).Configure();

to Application_Start fixed it.

Thank you all for your responses and help.

> --
> You received this message because you are subscribed to the Google Groups
> "Rhino Tools Dev" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/rhino-tools-dev/-/GGUe-rd9l-sJ.

Reply all
Reply to author
Forward
0 new messages