I have a messaging context object defined to be unique per incoming message processing:
Bind<MessagingContext>().ToSelf().InUnitOfWorkScope();
Also I registered a custom interface to be resolved dynamically via Ninject ToMethod extension:
Bind<IBus>().ToMethod(c =>
{
var messagingContext = c.Kernel.Get<MessagingContext>();
return new Bus(messagingContext);
});
Currently while resolving MessagingContext object instance I'm getting an exception:
Ninject.Extensions.NamedScope.UnknownScopeException
HResult=0x80131500
Message=Error activating MessagingContext
The scope NinjectObjectBuilder is not known in the current context.
No matching scopes are available, and the type is declared InNamedScope(NinjectObjectBuilder).
Is there any way to correctly resolve the object registered as InUnitOfWorkScope inside the ToMethod?
I'm using:
Seems like this might be a bug with child containers and named scoping.
As a work around in the meantime, you can change your MessagingContext registration to be:
Bind<MessagingContext>().ToSelf().DefinesNamedScope("NinjectObjectBuilder");
Which will at least let Ninject know that the MessagingContext type is intended to be used within the child container.
User contributions licensed under CC BY-SA 3.0