WCF with IOperationInvoker using Entity and Ninject -


i have wcf service need log calls methods. this, used this solution able track calls , call internal audit service, uses entity 5.1 , injects services/repositories/dbcontext using ninject.

my invoke method looks this:

    public object invoke(object instance, object[] inputs, out object[] outputs)     {         var methodparams = (instance).gettype().getmethod(_operationname).getparameters();         var parameters = new dictionary<string, object>();         (var index = 0; index < inputs.length; index++)             parameters.add(methodparams[index].name, inputs[index]);          _auditservice.trackfilterparametersvalues(_operation.parent.type.fullname, _operationname, _operation.action, parameters);          return _baseinvoker.invoke(instance, inputs, out outputs);     } 

in ninject module have internal stuff registered this:

bind<iauditservice>().to<auditeservice>().inrequestscope(); bind(typeof(irepository<>)).to(typeof(repository<>)).inrequestscope(); bind<iunitofwork>().to<unitofwork>().inrequestscope(); bind<dbcontext>().to<myentities>().inrequestscope(); 

problem comes when, inside repository, call dbcontext add new audit object this:

_dbcontext.set<t>().add(entity); 

it errors out claiming dbcontext has been disposed.

what correct way of registering dbcontext on wcf service gets registered ioperationinvoker??

i have mention have declaration same main site i'm feeding backend in mvc4 , works (no wcf there). i'm pretty sure needed corrected wcf lifetime cycle, not sure what.

i found reason of why behaving nasty: in chain formed ioperationinvoker, ioperationbehavior , iservicebehavior, injecting auditservice constructor of first 2 of them, in latest (iservicebehavior), since decorating wcf class , couldn't overload constructor, using dependencyresolver obtain auditservice property this:

public iauditservice auditservice {     { return dependencyresolver.current.getservice<iauditservice>(); } 

then, when started debug, noticed constructors called when wcf test client querying wcf wsdl data, invoke method never called because no web method being invoked. auditservice instance (and dbcontext) fine during calls of constructors, time of invoking web method , calling invoke method of ioperationinvoker, dbcontext disposed long time ago.

my workaround delete references auditservice constructors , move property dependencyresolver servicebehavior ioperationinvoker implementation. once did this, auditservice called right when it's needed, never before, , dbcontext never disposed.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -