Issues trying to use Windsor or Autofac

136 views
Skip to first unread message

Patrick Doran

unread,
May 9, 2013, 12:54:51 PM5/9/13
to masstrans...@googlegroups.com
I have put together a sample project where I am trying to use a Windsor Installer or Autofac Module to contain my setup for my service.  In registering my components both seem to have the same problem (perhaps my ignorance of IoC) but if I register with Windsor like so:

container.Register(Component.For<IConsumer>.ImplementedBy<Passenger>(),

I will get this:

ERROR 3 MassTransit.Transports.Endpoint - An exception was thrown preparing the message consumers
Castle.MicroKernel.ComponentNotFoundException: No component for supporting the service BusService.Consumers.Passenger was found
   at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
   at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments)
   at Castle.Windsor.WindsorContainer.Resolve[T]()
   at MassTransit.WindsorIntegration.WindsorConsumerFactory`1.<GetConsumer>d__0`1.MoveNext() in d:\BuildAgent-03\work\19b3d91f8acfae7a\src\Containers\MassTransit.WindsorIntegration\WindsorConsumerFactory.cs:line 36
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at MassTransit.Context.ServiceBusReceiveContext.<ReceiveFromEndpoint>b__0(IReceiveContext context) in d:\BuildAgent-03\work\19b3d91f8acfae7a\src\MassTransit\Context\ServiceBusReceiveContext.cs:line 102
   at MassTransit.Transports.Endpoint.<>c__DisplayClass9.<Receive>b__5(IReceiveContext acceptContext) in d:\BuildAgent-03\work\19b3d91f8acfae7a\src\MassTransit\Transports\Endpoint.cs:line 264

However,

container.Register(Component.For<Passenger>, works just fine.  Autofac has essentially the same problem, except it won't even register the consumer correctly (no errors, but nothing responds to the receipt of the message).

Here is my sample project: https://github.com/pdoran/BusStopFun

Jeramy Rutley

unread,
May 9, 2013, 2:00:34 PM5/9/13
to masstrans...@googlegroups.com
Passenger has to implement IConsumer if you want the line
container.Register(Component.For<IConsumer>.ImplementedBy<Passenger>(),
to work.  Right now the only interface it implements is Consumes<FareMessage>.Context

Dru Sellers

unread,
May 9, 2013, 2:06:01 PM5/9/13
to masstrans...@googlegroups.com
On top of that you'll need to register the concrete type not the interface if you use the built in MT container loadfrom

-d


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/masstransit-discuss/-/1SG2cHGDju4J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Patrick Doran

unread,
May 9, 2013, 2:10:43 PM5/9/13
to masstrans...@googlegroups.com
Jeramy,

I thought so too, however after changing Passenger to have this signature:

class Passenger : Consumes<FareMessage>.ContextIConsumer

I still get the same error.

Dru Sellers

unread,
May 9, 2013, 2:16:21 PM5/9/13
to masstrans...@googlegroups.com
Consumes<FareMessage>.Context is an interface that inherits from IConsumer. https://github.com/MassTransit/MassTransit/blob/master/src/MassTransit/Consumes.cs#L81

so that's already done. we don't look through the container via the interface because a consumer can have multiple interfaces on it. So we need the concrete types.

You can see the windsor test here:


-d


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Patrick Doran

unread,
May 9, 2013, 2:21:11 PM5/9/13
to masstrans...@googlegroups.com
Dru,

Brilliant, I had looked at that test case to see how it should work and figured out when switching to that method in my code was working. What is interesting is that Autofac and Windsor behave slightly differently, in that Autofac it never sets up the consumer where as with Windsor it does but then throws this error. I think it all makes sense now based on your comment. 

Thanks!

Dru Sellers

unread,
May 9, 2013, 2:22:29 PM5/9/13
to masstrans...@googlegroups.com
When I wrote this I was a much bigger StructureMap/Windsor guy - so if our autofac is weird you can blame me for that.

:)

-d


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Chris Patterson

unread,
May 9, 2013, 2:27:54 PM5/9/13
to masstrans...@googlegroups.com
It sounds like you have this figured out, but changing:


To just be

builder.RegisterType<Passenger>();

Should resolve the issue. You can also create a custom message scope, as is used by the AutofacConsumerFactory, so that dependencies of
the consumer class can be instantiated within the lifetime scope of the message consumer.



--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Patrick Doran

unread,
May 9, 2013, 2:33:22 PM5/9/13
to masstrans...@googlegroups.com
Chris,

I do, but that extra tidbit of info is great to know, because it was what I was going to investigate next! 

Thanks for the replies guys!
Reply all
Reply to author
Forward
0 new messages