From 05767d6afc8fb31770a470be9287f33d46b28b6e Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 5 Apr 2019 21:10:14 -0400 Subject: [PATCH] Switch to using NuGet package for listing all registered services --- src/Web/Startup.cs | 45 +++++++++++---------------------------------- src/Web/Web.csproj | 1 + 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index 742a92656..5b57d1786 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Builder; +using Ardalis.ListStartupServices; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -23,9 +24,9 @@ using Newtonsoft.Json; using Swashbuckle.AspNetCore.Swagger; using System; +using System.Collections.Generic; using System.Linq; using System.Net.Mime; -using System.Text; namespace Microsoft.eShopWeb.Web { @@ -133,6 +134,13 @@ public void ConfigureServices(IServiceCollection services) .AddCheck("home_page_health_check") .AddCheck("api_health_check"); + services.Configure(config => + { + config.Services = new List(services); + + config.Path = "/allservices"; + }); + _services = services; // used to debug registered services } @@ -200,7 +208,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, LinkGene if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - ListAllRegisteredServices(app, linkGenerator); + app.UseShowAllServicesMiddleware(); app.UseDatabaseErrorPage(); } else @@ -237,36 +245,5 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, LinkGene template: "{controller:slugify=Home}/{action:slugify=Index}/{id?}"); }); } - - private void ListAllRegisteredServices(IApplicationBuilder app, LinkGenerator linkGenerator) - { - var homePageLink = linkGenerator.GetPathByAction("Index", "Catalog"); - var loginLink = linkGenerator.GetPathByAction("SignIn", "Account"); - app.Map("/allservices", builder => builder.Run(async context => - { - var sb = new StringBuilder(); - sb.Append("Return to site | "); - sb.Append("Login to site"); - sb.Append("

All Services

"); - sb.Append(""); - sb.Append(""); - sb.Append(""); - foreach (var svc in _services) - { - sb.Append(""); - sb.Append($""); - sb.Append($""); - sb.Append($""); - sb.Append(""); - } - sb.Append("
TypeLifetimeInstance
{svc.ServiceType.FullName}{svc.Lifetime}{svc.ImplementationType?.FullName}
"); - await context.Response.WriteAsync(sb.ToString()); - })); - } - } } diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 0b31d11b7..edb0d0ec4 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -13,6 +13,7 @@ +