using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; namespace New_College.Extensions { /// /// 查看所有注入的服务 /// public static class AllServicesMildd { public static void UseAllServicesMildd(this IApplicationBuilder app, IServiceCollection _services) { if (app == null) throw new ArgumentNullException(nameof(app)); List tsDIAutofac = new List(); tsDIAutofac.AddRange(Assembly.LoadFrom(Path.Combine(AppContext.BaseDirectory, "New_College.Services.dll")).GetTypes().ToList()); tsDIAutofac.AddRange(Assembly.LoadFrom(Path.Combine(AppContext.BaseDirectory, "New_College.Repository.dll")).GetTypes().ToList()); app.Map("/allservices", builder => builder.Run(async context => { context.Response.ContentType = "text/html; charset=utf-8"; await context.Response.WriteAsync(""); await context.Response.WriteAsync($"

所有服务{_services.Count}个

"); foreach (var svc in _services) { await context.Response.WriteAsync(""); await context.Response.WriteAsync($""); await context.Response.WriteAsync($""); await context.Response.WriteAsync($""); await context.Response.WriteAsync(""); } foreach (var item in tsDIAutofac.Where(s => !s.IsInterface)) { var interfaceType = item.GetInterfaces(); foreach (var typeArray in interfaceType) { await context.Response.WriteAsync(""); await context.Response.WriteAsync($""); await context.Response.WriteAsync($""); await context.Response.WriteAsync($""); await context.Response.WriteAsync(""); } } await context.Response.WriteAsync("
类型生命周期Instance
{svc.ServiceType.FullName}{svc.Lifetime}{svc.ImplementationType?.Name}
{typeArray?.FullName}Scoped{item?.Name}
"); })); } } }