This project is read-only.

WCF SimpleInjector

Jan 22, 2014 at 4:14 AM
Edited Jan 22, 2014 at 4:31 AM

I am using Simple Injector and SimpleInjector.Integration.Wcf
I think i am using the Wcf part in the Wrong way.

what I want to achieve:
I Using EF and I have a DbContext with DbSet inside.
I use This Dbcontext in Command pattern.
I want to have a PerWcfOperation lifecycle on my context. Which means i want a new context for each request.

But when I am using, it 1 time on 3 or 4 My context is not newly construct.
I arrive directly in the constructor of the command handler without going through the Context constructor. So The context I assume that the command Handler i get, is the same than in the previous request
It's happening when I am doing several request from the same client to the WCF service

For the code below how i manage the container configuration (I simplified it)
Container container = new Container();
container.RegisterManyForOpenGeneric(typeof(ICommandHandler<,>),  Assembly.GetExecutingAssembly());
 container.RegisterDecorator(typeof(ICommandHandler<,>), typeof(MonitoringCommandHandlerDecorator<,>));

container.RegisterPerWcfOperation<MyContext>(()=> new MyContext());

ServiceHost host = new SimpleInjectorServiceHost(containerWcf, typeof(MyService), baseAddress);
for the command Handler i also try to configure it with new WcfOperationLifestyle().

Did i miss something? On the concept? on the code?

EDIT: I use the lifetimeScope decribe here
and it work well.
But i am curious what did i do wrong in my previous solution.

Thanks a lot.
Jan 22, 2014 at 7:25 AM
Your configuration looks correct, so I'm not sure what's going wrong here. The integration package should simply serve a new instance per WCF operation; per service call. In your code sample however, you are creating a container, but supplying a containerWcf to the SimpleInjectorServiceHost, but I expect this to be a typo in your question; not in your application.

What I noticed is that you are mixing two versions of Simple Injector. Although I don't think anything has changed between SimpleInjector.Integration.Wcf and SimpleInjector.Integration.Wcf, it's always good to keep those versions in sync.
Feb 26, 2014 at 8:18 PM
>> But when I am using, it 1 time on 3 or 4 My context is not newly construct.

Might this been caused by this bug: WcfOperationLifestyle works as session lifestyle?
Marked as answer by dot_NET_Junkie on 4/15/2014 at 1:46 AM