title: How to add configuration settings into _Layout.cshtml shared Razor page
body: <p>We have this <code>StartUp</code> as follow that getting values from <code>appsettings.json</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public Startup(IHostingEnvironment env)
  {
      var builder = new ConfigurationBuilder()
          .SetBasePath(env.ContentRootPath)
          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
          .AddEnvironmentVariables();
      Configuration = builder.Build();
  
      var environment = Configuration["ApplicationSettings:Environment"];
  }
  
  public void ConfigureServices(IServiceCollection services)
  {
      services.Configure&lt;AppSettings&gt;(Configuration.GetSection("ApplicationSettings"));
  
      ...
  }
  </code></pre>
  
  <p>And we also model called <code>AppSettings</code> </p>
  
  <pre class="lang-cs prettyprint-override"><code>public class AppSettings
  {
      public string Environment { get; set; }
      public string Version { get; set; }
  }
  </code></pre>
  
  <p>As I'm working on <code>/Pages/Shared/_Layout.cshtml</code> trying to inject this <strong>Version</strong> into this shared page, I could not do the code behind approach. How do inject this then?</p>
  
  <p><strong>UPDATES 1 -</strong></p>
  
  <p>In theory I could do like this if it's a page model:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class _LayoutModel : PageModel
  {
      private readonly AppSettings _appSettings;
  
      public string Version;
      public string Environment;
  
      public _LayoutModel(IOptions&lt;AppSettings&gt; appsettings)
      {
          _appSettings = appsettings.Value;
      }
  
      public void OnGet()
      {
          Environment = _appSettings.Environment;
          Version = _appSettings.Version;
      }
  }
  </code></pre>