public TResult Invoke <TResult>(AspectActivatorContext activatorContext) { var context = _aspectContextFactory.CreateContext(activatorContext); try { var aspectBuilder = _aspectBuilderFactory.Create(context); var task = aspectBuilder.Build()(context); if (task.IsFaulted) { throw _aspectExceptionWrapper.Wrap(context, task.Exception.InnerException); } if (!task.IsCompleted) { // try to avoid potential deadlocks. NoSyncContextScope.Run(task); // task.GetAwaiter().GetResult(); } return((TResult)context.ReturnValue); } catch (Exception ex) { throw _aspectExceptionWrapper.Wrap(context, ex); } finally { _aspectContextFactory.ReleaseContext(context); } }
public TResult Invoke <TResult>(AspectActivatorContext activatorContext) { var context = _aspectContextFactory.CreateContext(activatorContext); try { var aspectBuilder = _aspectBuilderFactory.Create(context); var task = aspectBuilder.Build()(context); if (task.IsFaulted) { throw context.InvocationException(task.Exception); } else if (!task.IsCompleted) { task.GetAwaiter().GetResult(); } return((TResult)context.ReturnValue); } catch (Exception ex) { throw context.InvocationException(ex); } finally { _aspectContextFactory.ReleaseContext(context); } }
public TResult Invoke <TResult>(AspectActivatorContext activatorContext) { var context = aspectContextFactory.CreateContext(activatorContext); try { var aspectBuilder = aspectBuilderFactory.Create(context); var task = aspectBuilder.Build()(context); if (task.IsFaulted) { throw task.Exception.InnerException; } if (!task.IsCompleted) { // try to avoid potential deadlocks. NoSyncContextScope.Run(task); } return((TResult)context.ReturnValue); } finally { aspectContextFactory.ReleaseContext(context); } }
public TResult Invoke <TResult>(AspectActivatorContext activatorContext) { using (var context = _aspectContextFactory.CreateContext(activatorContext)) { var aspectBuilder = _aspectBuilderFactory.Create(context); var invoke = aspectBuilder.Build()(context); if (invoke.IsFaulted) { var innerException = invoke.Exception?.InnerException; throw context.InvocationException(innerException); } if (!invoke.IsCompleted) { invoke.GetAwaiter().GetResult(); } return((TResult)context.ReturnValue); } }
public async Task <TReturn> InvokeAsync <TReturn>(AspectActivatorContext activatorContext) { using (var context = _aspectContextFactory.CreateContext <TReturn>(activatorContext)) { var aspectBuilder = _aspectBuilderFactory.Create(context); await aspectBuilder.Build()(() => context.Target.Invoke(context.Parameters))(context); return(await Unwrap <TReturn>(context.ReturnParameter.Value)); } }
public TResult Invoke <TResult>(AspectActivatorContext activatorContext) { var context = _aspectContextFactory.CreateContext(activatorContext); try { var aspectBuilder = _aspectBuilderFactory.Create(context); var invoke = aspectBuilder.Build()(context); if (invoke.IsFaulted) { var innerException = invoke.Exception?.InnerException; throw context.InvocationException(innerException); } return((TResult)context.ReturnValue); } finally { _aspectContextFactory.ReleaseContext(context); } }