title: Access @Inject variable in @code - .net Core Blazor
body: <p>I am new to Blazor .net Core. I have injected service settings in my .razor page </p>
  
  <pre><code>@inject Microsoft.Extensions.Options.IOptions&lt;Configuration&gt; Configuration
  </code></pre>
  
  <p>Next I have <code>@code</code> directive below that initialise the _m object </p>
  
  <pre><code>@code 
  {
      private ViewModel _m = new ViewModel(Configuration.Value);
  
      protected async Task DoSearchAsync()
      {
          await _m.PerformSearchAsync();
      }
  }
  </code></pre>
  
  <p>Registered code in <strong>ConfigureServices</strong>:</p>
  
  <pre><code>services.Configure&lt;Configuration&gt;(options =&gt; 
      Configuration.GetSection("ConfigurationSettings").Bind(options));
  </code></pre>
  
  <p><strong>Configuration.cs</strong></p>
  
  <pre><code>public class Configuration
  {
      private string ServiceEndpointUrl { get; set; }
  }
  </code></pre>
  
  <p>I need to pass the Configuration to <code>ViewModel()</code> constructor that takes <code>IOptions&lt;T&gt;</code>, but for some reason I cannot access my injected variable "Configuration" in <code>@code</code> directive. How do I access that please?</p>