【发布时间】:2020-12-16 07:05:41
【问题描述】:
我正在尝试编写自定义运行状况检查并将其放入 Nuget 以供重复使用。要让应用程序 (.netcore 3.1) 使用此运行状况检查,它需要调用
appBuilder.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health", new HealthCheckOptions
{
ResultStatusCodes =
{
[HealthStatus.Healthy] = StatusCodes.Status200OK,
[HealthStatus.Degraded] = StatusCodes.Status200OK,
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
},
AllowCachingResponses = false,
ResponseWriter = HealthCheckResponseWriter.WriteResponse
});
});
除了 ConfigureServices 中的其他调用。 我想将这部分代码移动到我的 nuget 中,但遇到了不明白我需要使用什么 Nuget 才能在我的类库中同时使用 IApplicationBuilder 和 UseEndpoints 扩展方法?事实证明,我可以在使用 .NET.Sdk.Web 的其他应用程序中做到这一点而不会出现任何问题,但在类库中却没有。看起来它所需的所有依赖项都隐式添加到了 web sdk 中,但是我怎样才能弄清楚我应该在类库中添加什么才能使其工作?
【问题讨论】:
标签: nuget extension-methods asp.net-core-3.1