Base solution for your next web application
Open Closed

Adding a setting and making it available in the _layout.html #434


User avatar
0
john_kattenhorn created

Hi,

I have the requirement to add a setting to enable on a per-tenant basis NewRelic DevOps integration. Part of this requires inserting a script into the layout page which I only want to insert if the setting is set in the Tenant Manager.

I think I've got most of the steps needed but I'm a little stuck as to how to make the settings manager available to the page in the same way as LocalisationManager is e.g. @L("")

Do I need to extend WebViewPageBase ? If so how could I inject the settings manager into it so I can do something like :

SettingManager.GetSettingValueForTenantAsync<bool>(AppSettings.DevOps.UseNewRelic, tenant.Id))

Any guidance would be most appreciated.


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    You can add setting manager to your viewpagebase (It's name should be ProjectNameWebViewPageBase).

    public abstract class AbpZeroTemplateWebViewPageBase<TModel> : AbpWebViewPage<TModel>
        {
            public ISettingManager SettingManager { get; set; }
    
            protected AbpZeroTemplateWebViewPageBase()
            {
                LocalizationSourceName = AbpZeroTemplateConsts.LocalizationSourceName;
                SettingManager = IocManager.Instance.Resolve<ISettingManager>();
            }
        }
    

    Then you can use @SettingManager in all razor views.