我一直在努力找出asp网络核心附带的依赖关系模式。这是我要实现的目标。
_ViewImports.cshtml
...
@inject AdminBuilder AdminBuilder
...
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddHttpContextIshSingleton<AdminBuilder>();
...
}
AnyCSHtmlFile.cshtml
@AdminBuilder.AddStuff()
@AdminBuilder.EnableStuff()
@AdminBuilder.DoStuff()
// It'll then populate the AdminBuilder instance, which needs to be a unique instance for each visit.
Layout.cshtml
这里,我将根据呈现页面时添加的内容,从.cshtml部分文件的底部呈现AdminBuilder。
答案 0 :(得分:1)
使用capitals_listings_from_latest_Celery_scrape
。
您可以在官方文档中进一步了解内置生命周期:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1#service-lifetimes