如何在主题视图中访问 Cofoundry 设置和其他注入的依赖项 类

How do I access Cofoundry settings and other dependency injected classes in theme views

我已经定义了一个设置 class,其中包含特定于主题的设置 - 在本例中,网站的主标题:

public class ThemeSettings : IConfigurationSettings
{
    [Required]
    public string SiteTitle { get; set; }
}

现在我想在我的 _Layout.cshtml 文件中包含网站标题:

_Layout.cshtml:

<h2 class="header-title">  ... INSERT TITLE HERE ... </h2>

但是我怎样才能在没有控制器的情况下将 ThemeSettings class 注入到视图文件中,以便我可以访问 属性 SiteTitle

Razor 文件在 ASP.NET 核心中支持依赖注入:

@inject ThemeSettings themeSettings 

<h2 class="header-title">@themeSettings.SiteTitle</h2>