/// <summary> /// *POI /// Microsoft's implementation of IApplicationBuilder injects the RequestDelegate object. So /// that parameter is required and it needs to be the first parameter in the constructor of /// all middleware classes. The other parameters are objects we inject in Step 2. /// </summary> /// <param name="next">Represents the next module in the http pipeline.</param> /// <param name="loggerFactory">The LoggerFactory object from the Startup.Configure() method.</param> /// <param name="responseTimer">An instantiated ResponseTimer object.</param> public ResponseTimeLogger(RequestDelegate next, ILoggerFactory loggerFactory, ResponseTimer responseTimer) { this.next = next; this.loggerFactory = loggerFactory; this.responseTimer = responseTimer; }
/// <summary> /// *POI Step 2 /// This extension method does two things. /// 1. Gives us a way to add our custom middleware class to the Http Pipeline. /// 2. Injects our dependencies into the ApplicationBuilder class. /// </summary> /// <param name="builder">Required to extend the ApplicationBuilder class.</param> /// <param name="loggerFactory">The LoggerFactory object from the Startup.Configure() method.</param> /// <param name="responseTimer">An instantiated ResponseTimer object.</param> /// <returns></returns> public static IApplicationBuilder UseResponseTimer(this IApplicationBuilder builder, ILoggerFactory loggerFactory, ResponseTimer responseTimer) { //This method will accept a parameter array but I always explicitly define parameter arrays. return(builder.UseMiddleware <ResponseTimeLogger>(new object[] { loggerFactory, responseTimer })); }