Problem:
A request sent to the WCF service, the caller IBus.SendLocal, creates two instances of the object configured asInstancePerLifetimeScope()
Background:
I use Autofac.Integration.WCF(which makes everything resolved "per request", providing a new child scope for each WCF request)
IBus.SendLocal invokes a message mutator that receives the same resource type as the wcf service
However, two different instances are created. One is entered into the service, the other instance is entered into the message mutator.
I assume this is because the NSB creates its own child region based on the root container.
Any ideas / pointers on how to solve this problem (i.e. create only one instance created for each WCF request)?
Edit: using NSB 4.3.2 and Autofac 3.5.2
Simplified configuration code
Autofac.IContainer container = ConfigureIoc();
Configure
.With(AllAssemblies.Matching("this.dll").And("that.dll"))
.DefineEndpointName("endpoint name here")
.AutofacBuilder(container)
.MsmqSubscriptionStorage()
.UnicastBus()
.CreateBus()
.Start();
ServiceHost host = CreateHost();
host.AddDependencyInjectionBehavior(typeof(ISomeContract), container);
host.Open();
source
share