I'm attempting to use EasyNetQ with Ninject to log messages.
I've managed to setup Ninject as the EasyNetQ DI (I think), but when a message comes to a handler without a parameterless constructor (e.g. I need a repository bound in there), it doesn't resolve. Or atleast I believe that's the issue as I get a pretty generic error on the console.
I tell EasyNetQ to use Ninject like so :
RabbitHutch.SetContainerFactory(() => new NinjectAdapter(container));
I think this is all I need to set it up. The Ninject Adapter is the one from EasyNetQ.
My handler looks like the following :
public class ProfileDeactivatedUpdateHandler : IConsume<ProfileDeactivatedUpdate>
{
private readonly IProfileRepository _profileRepository;
public ProfileDeactivatedUpdateHandler(IProfileRepository profileRepository)
{
_profileRepository = profileRepository;
}
public void Consume(ProfileDeactivatedUpdate message)
{
//Do Stuff.
}
}
If I add a parameterless constructor, and instead setup Ninject to be available through the ServiceLocator (Ugh), then it works. The handler is called fine, and I can find my repository via the ServiceLocator, So I know that atleast Ninject knows about the repository.
The error that pops up when it tries to handle a message is.
System.AggregateException: One or more errors occurred. ---> System.Exception: E
xception of type 'System.Exception' was thrown.
at EasyNetQ.ReflectionHelpers.DefaultFactories`1.Get()
at EasyNetQ.ReflectionHelpers.CreateInstance[T]()
at EasyNetQ.AutoSubscribe.DefaultAutoSubscriberMessageDispatcher.Dispatch[TMe
ssage,TConsumer](TMessage message)
at EasyNetQ.RabbitBus.<>c__DisplayClass6`1.<Subscribe>b__5(T msg)
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.Exception: Exception of type 'System.Exception'
was thrown.
at EasyNetQ.ReflectionHelpers.DefaultFactories`1.Get()
at EasyNetQ.ReflectionHelpers.CreateInstance[T]()
at EasyNetQ.AutoSubscribe.DefaultAutoSubscriberMessageDispatcher.Dispatch[TMe
ssage,TConsumer](TMessage message)
at EasyNetQ.RabbitBus.<>c__DisplayClass6`1.<Subscribe>b__5(T msg)<---