private IApiResponseContextDto <TOut> ScopeWrap <TRequestDto, TOut>(TRequestDto requestDto, ILifetimeScope scope, string token) where TRequestDto : IApiRequestDto { _log.Debug(this.GetType().Name, requestDto.GetType().Name, "START"); var context = scope.Resolve <IExecutionPipelineContext <TOut> >(); if (!string.IsNullOrWhiteSpace(token)) { scope.Resolve <ITokenCache>().Set(token); } try { foreach (var type in _types) { var handler = scope.Resolve(type); handler.GetType() .GetMethod("Handle") .Invoke(handler, new[] { (object)requestDto }); if (context.HasErrors()) { return(scope.Resolve <IMapper>().Map <IApiResponseContextDto <TOut> >(context)); } } return(scope.Resolve <IMapper>().Map <IApiResponseContextDto <TOut> >(context)); } catch (Exception e) { var errorGuid = $"{DateTime.Now:MMddyyyyHHmmss}" + $"_{scope.Resolve<IApplicationUserContext>()?.Id}"; //_log.Fatal(errorGuid, e); _log.Debug(this.GetType().Name, requestDto.GetType().Name, $"{errorGuid} -- ERROR MESSAGE: {e.Message} INNER EXCEPTION: {e.InnerException} STACKTRACE: {e.StackTrace}"); context.AddMessage("E2", errorGuid); return(scope.Resolve <IMapper>().Map <IApiResponseContextDto <TOut> >(context)); } finally { _log.Debug(this.GetType().Name, requestDto.GetType().Name, "END"); LogMessages(requestDto, context); //scope.Dispose(); } }
private IApiResponseContextDto <TOut> ScopeWrap <TRequestDto, TOut>(TRequestDto requestDto, ILifetimeScope scope, string token) where TRequestDto : IApiRequestDto { _log.Debug(this.GetType().Name, requestDto.GetType().Name, "START"); var context = scope.Resolve <IExecutionPipelineContext <TOut> >(); if (!string.IsNullOrWhiteSpace(token)) { scope.Resolve <ITokenCache>().Set(token); } try { foreach (var type in _types) { ((IExecutionPipelineFilter <TRequestDto, TOut>) scope.Resolve(type.MakeGenericType (typeof(TRequestDto), typeof(TOut)))) .Participate(requestDto); if (context.Messages.Any(a => a.Type == MessageDtoType.Error)) { return(scope.Resolve <IMapper>().Map <IApiResponseContextDto <TOut> >(context)); } } return(scope.Resolve <IMapper>().Map <IApiResponseContextDto <TOut> >(context)); } catch (Exception e) { var errorGuid = $"{DateTime.Now:MMddyyyyHHmmss}" + $"_{scope.Resolve<IApplicationUserContext>()?.Id}"; //_log.Fatal(errorGuid, e); _log.Fatal(this.GetType().Name, requestDto.GetType().Name, $"{errorGuid} -- ERROR MESSAGE: {e.Message} INNER EXCEPTION: {e.InnerException} STACKTRACE: {e.StackTrace}"); context.AddMessage("E2", errorGuid); return(scope.Resolve <IMapper>().Map <IApiResponseContextDto <TOut> >(context)); } finally { _log.Debug(this.GetType().Name, requestDto.GetType().Name, "END"); LogMessages(requestDto, context); //scope.Dispose(); } }