You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When configuring an interception policy that uses a CallHandler which it depends upon injection of other services registered in the container, the lifetime is ignored and the same instance of the call handler is used for different resolution contexts.
And considder that the LogCallHandler is defined as
publicclassLogCallHandler:ICallHandler{publicstaticintInstanceCount{get;privateset;}privatereadonlyILoglog;publicLogCallHandler(ILoglog){this.log=log;ObjectInstance=++InstanceCount;}publicintOrder{get;set;}publicintObjectInstance{get;}publicIMethodReturnInvoke(IMethodInvocationinput,GetNextHandlerDelegategetNext){varmethod=$"{input.MethodBase.DeclaringType}.{input.MethodBase.Name}";log.Write($"{method} - starting invocation by call handler instance {ObjectInstance}");varresult=getNext()(input,getNext);log.Write($"{method} - invocation ended by call handler instance {ObjectInstance}");returnresult;}}
Depending on the set of libraries used (as described on the first section) the second assert will succeed or fail.
You'd expect that the call handler is resolved by the container in the same way as any other type, according to what the lifetime manager dictates.
Additional context
This might look trivial at a first glance, but when using a LifetimeManager such as the PerRequestLifetimeManager and when the injected member for the CallHandler is something that can't be treated as a singleton, a big problem arises (for instance: the object will be already disposed when the call handler tryes to use it on the second round).
I have both a unit test project as well as a realistic web application with this behavior which I'm happy to provide. I've tried to go into the belly of Unity to understand this better, but got a bit lost when doing so. If I happen to discover more details on the source of the problem will update this (and if I get it right, even send you a pull request).
The text was updated successfully, but these errors were encountered:
ENikS
transferred this issue from unitycontainer/unity
Dec 3, 2018
Description
When configuring an interception policy that uses a
CallHandler
which it depends upon injection of other services registered in the container, the lifetime is ignored and the same instance of the call handler is used for different resolution contexts.This used to work fine up to:
But started failing on the next release:
To Reproduce
See the following test
And considder that the
LogCallHandler
is defined asDepending on the set of libraries used (as described on the first section) the second assert will succeed or fail.
You'd expect that the call handler is resolved by the container in the same way as any other type, according to what the lifetime manager dictates.
Additional context
This might look trivial at a first glance, but when using a LifetimeManager such as the
PerRequestLifetimeManager
and when the injected member for the CallHandler is something that can't be treated as a singleton, a big problem arises (for instance: the object will be already disposed when the call handler tryes to use it on the second round).I have both a unit test project as well as a realistic web application with this behavior which I'm happy to provide. I've tried to go into the belly of Unity to understand this better, but got a bit lost when doing so. If I happen to discover more details on the source of the problem will update this (and if I get it right, even send you a pull request).
The text was updated successfully, but these errors were encountered: