【发布时间】:2021-07-09 14:58:47
【问题描述】:
我有一个注册其服务的库:
public static IServiceCollection AddViewStringRenderer(this IServiceCollection services, string contentRootPath, ILogger logger)
{
services.Configure<RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new ViewLocationExpander(contentRootPath, logger)); });
services.AddTransient<IRazorViewToStringRenderer, RazorViewToStringRenderer>();
...
return services;
}
如您所见,我需要一个用于services.Configure<RazorViewEngineOptions>(...) 的记录器,因此它是此扩展方法的一个参数。
但由于该方法用于Startup.ConfigureServices(),我们无法在.NET 5 中实例化ILogger。如何将记录器传递给services.Configure()?
【问题讨论】:
标签: c# asp.net-core dependency-injection .net-5