Closed
Description
This question was migrated from CodePlex discussion #578166
Post date: 2015-01-20 10:24:30
We are migrating away from Unity and would like to use Simple Injector as we've read it has great performance.
I am now looking at interception as described here.
But one thing I have a question on is: Does anyone have sample code to make this work for async methods? e.g. below is example usage -- where invocation.Proceed() is a synchronous call.
public void Intercept(IInvocation invocation) {
var watch = Stopwatch.StartNew();
// Calls the decorated instance.
invocation.Proceed();
var decoratedType = invocation.InvocationTarget.GetType();
this.logger.Log(string.Format("{0} executed in {1} ms.",
decoratedType.Name, watch.ElapsedMiliseconds));
}
FYI: In Unity, we solved the problem as outlined here:
The basic approach adopted there was to wrap the call in a task.
http://msdn.microsoft.com/en-us/magazine/dn574805.aspx
Thanks!