public async Task InvokeAsync(HttpContext context, VodafoneExceptionDbContext exceptiondbContext) { try { // if no exception while processing the request move to next middleware await request(context); } catch (Exception ex) { exceptiondbContext.ExceptionLogs.Add(new ExceptionLog { ExceptionMesaage = ex.Message, Date = DateTime.Now }); exceptiondbContext.SaveChanges(); // logic for exception handling and generating response await HandleErrorAndWriteResponse(context, ex); } }
/// <summary> /// Inject IModelMetadataProvider /// This interface is resolved by MvcOptions in ConfigureServices() /// </summary> public MyExceptionFilterAttribute(IModelMetadataProvider modelMetadata, VodafoneExceptionDbContext dbContext) { this.modelMetadata = modelMetadata; this.dbContext = dbContext; }