Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Bergman 483 posts 1132 karma points
    May 12, 2021 @ 22:05
    John Bergman
    0

    GlobalSettings in a SurfaceController?

    Can anyone point me to where/how I would get the IGlobalSetings object while executing in a SurfaceController?

  • AddWeb Solution Pvt. Ltd 109 posts 360 karma points
    May 21, 2021 @ 05:32
    AddWeb Solution Pvt. Ltd
    0

    Hello John,

    The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information from web.config appsettings check this https://our.umbraco.com/apidocs/v8/csharp/api/Umbraco.Core.Configuration.GlobalSettings.html

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    May 21, 2021 @ 06:56
    Nik
    100

    Hi John,

    In V8 you should be able to take advantage of DI to get access to that.

    I would try something like this:

    public classs MySurfaceController : SurfaceController
    {
           private readonly IGlobalSettings globalSettings;
    
           public MySurfaceController(IGlobalSettings globalSettings)
           {
                   this.globalSettings = globalSettings;
           }
    
           public ActionResult MyAction()
           {
                   //do something with globalSettings 
           }
    }
    

    This should allow you access to that object assuming it is registered with the DI container. If it's not, I'm sure there will be a similar object that might wrap the global settings that can be injected.

    Thanks

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft