Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 056a3b3

Browse files
committed
commit
2 parents f09037e + 0fe4413 commit 056a3b3

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

HttpReports.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
44
VisualStudioVersion = 16.0.29411.108
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BAF971BD-0546-4610-A9F6-6F6DC68E6FE7}"
7+
ProjectSection(SolutionItems) = preProject
8+
src\LICENSE = src\LICENSE
9+
EndProjectSection
710
EndProject
811
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpReports", "src\HttpReports\HttpReports.csproj", "{0A9D3AD0-3747-47CD-AD7C-4CB907E65C04}"
912
EndProject
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System;
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.Extensions.Configuration;
3+
using System;
4+
using System.Collections.Generic;
25
using System.Diagnostics;
6+
using System.Text;
37
using System.Threading.Tasks;
48

5-
using Microsoft.AspNetCore.Http;
6-
using Microsoft.Extensions.Configuration;
7-
89
namespace HttpReports
910
{
1011
public class HttpReportsMiddleware
@@ -15,27 +16,26 @@ public class HttpReportsMiddleware
1516

1617
private IHttpReports _httpReports;
1718

18-
private IConfiguration _Configuration;
19+
public static IConfiguration Configuration;
1920

20-
public HttpReportsMiddleware(RequestDelegate next, IHttpReports httpReports, IConfiguration configuration)
21+
public HttpReportsMiddleware(RequestDelegate next, IHttpReports httpReports)
2122
{
2223
this._next = next;
2324
this._httpReports = httpReports;
24-
this._Configuration = configuration;
25+
this._httpReports.Init(Configuration);
2526

26-
this._httpReports.Init(configuration);
2727
}
2828

2929
public async Task InvokeAsync(HttpContext context)
3030
{
3131
stopwatch = new Stopwatch();
32-
stopwatch.Start();
32+
stopwatch.Start();
3333

34-
await Execute(context);
34+
await Execute(context);
3535

36-
stopwatch.Stop();
37-
_httpReports.Invoke(context, stopwatch.Elapsed.TotalMilliseconds, _Configuration);
38-
}
36+
stopwatch.Stop();
37+
_httpReports.Invoke(context, stopwatch.Elapsed.TotalMilliseconds, Configuration);
38+
}
3939

4040
private async Task Execute(HttpContext context)
4141
{
@@ -46,7 +46,8 @@ private async Task Execute(HttpContext context)
4646
catch (Exception ex)
4747
{
4848
context.Response.StatusCode = 500;
49-
}
50-
}
51-
}
52-
}
49+
}
50+
}
51+
52+
}
53+
}
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System;
2-
3-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
42
using Microsoft.Extensions.DependencyInjection;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
using Microsoft.Extensions.Configuration;
57

68
namespace HttpReports
79
{
@@ -10,32 +12,35 @@ public static class HttpReportsMiddlewareExtensions
1012
/// <summary>
1113
/// 添加HttpReports中间件
1214
/// </summary>
13-
/// <param name="services"></param>
14-
/// <param name="options"></param>
15+
/// <param name="services">The services.</param>
16+
/// <param name="configuration">The configuration.</param>
17+
/// <param name="webType">Type of the web.</param>
18+
/// <param name="dbType">Type of the database.</param>
19+
/// <param name="Node">The node.</param>
1520
/// <returns></returns>
16-
public static IServiceCollection AddHttpReportsMiddleware(this IServiceCollection services, WebType webType, DBType dbType, string Node = "Default")
21+
public static IServiceCollection AddHttpReportsMiddleware(this IServiceCollection services, IConfiguration configuration, WebType webType, DBType dbType,string Node = "Default")
1722
{
1823
Action<HttpReportsOptions> options = (op) =>
1924
{
2025
op.DBType = dbType;
2126
op.WebType = webType;
22-
op.Node = string.IsNullOrEmpty(Node) ? "Default" : Node;
23-
};
27+
op.Node = string.IsNullOrEmpty(Node) ? "Default":Node;
28+
};
2429

2530
services.AddOptions();
2631
services.Configure(options);
27-
32+
HttpReportsMiddleware.Configuration = configuration;
2833
return services.AddTransient<IHttpReports, DefaultHttpReports>();
29-
}
34+
}
3035

3136
/// <summary>
3237
/// 使用 HttpReports, 必须放在UseMvc之前
3338
/// </summary>
3439
/// <param name="app"></param>
3540
/// <returns></returns>
3641
public static IApplicationBuilder UseHttpReportsMiddleware(this IApplicationBuilder app)
37-
{
42+
{
3843
return app.UseMiddleware<HttpReportsMiddleware>();
3944
}
4045
}
41-
}
46+
}

0 commit comments

Comments
 (0)