title: Blazor Client-Side (WebAssembly) reading a json file on startup.cs
body: <p>Since <code>appsettings.json</code> does not work very well with  blazor WA, i am creating my own and putting a <code>.json</code> file in <code>wwwroot</code>, in the pages that require it, i use the <code>HttpClient</code> to get to the file as follow
  <code>config = await Http.GetJsonAsync&lt;Configuration&gt;("/config/appsettings.json");</code></p>
  
  <p>This works great, however I am doing this in multiple pages, so I would like to inject <code>Configuration</code> object/service at startup.cs and have my pages use that instead of doing this multiple times.</p>
  
  <p>I am having a hard time finding out how to properly read the file in Startup.cs, any help would be appreciated.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>It seems that <code>App.OnInitializedAsync</code> is being fired before <code>Index.OnInitializedAsync</code> but the <code>Settings = await httpClient.GetJsonAsync&lt;Settings&gt;("/config/appsettings.json").ConfigureAwait(false);</code> taking longer which is causing <code>App.OnInitializedAsync</code> to execute BEFORE the above line.</p>
  
  <p>here is all the code</p>
  
  <p>Startup.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public class Startup
      {
  
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddSingleton&lt;ConfigurationManager&gt;();
              services.AddBlazoredToast();
          }
          public void Configure(IComponentsApplicationBuilder app)
          {
              app.AddComponent&lt;App&gt;("app");
          }
  
      }
  </code></pre>
  
  <p>App.razor</p>
  
  <pre class="lang-cs prettyprint-override"><code>    protected override async Task OnInitializedAsync()
      {
  
          Console.WriteLine("App.OnInitializedAsync");
          await configManager.InitializeAsync();
  
      }
  </code></pre>
  
  <p>Index.razor</p>
  
  <pre class="lang-cs prettyprint-override"><code>
      protected override async Task OnInitializedAsync()
      {
          Console.WriteLine("Index.OnInitializedAsync");
  
  
          //config = await Http.GetJsonAsync&lt;Configuration&gt;("/config/appsettings.json");
          if (configManager == null)
          {
              Console.WriteLine("Index.OnInitializedAsync config manager is null");
          }
          else
          {
              if (configManager.Settings == null)
              {
                  Console.WriteLine("Index.OnInitializedAsync config.Settings is null");
              }
              else
              {
                  Console.WriteLine("base url" + configManager.Settings.ApiBaseUrl);
  
              }
          }
      }
  </code></pre>
  
  <p>Here is the sequence</p>
  
  <pre><code>WASM: App.OnInitializedAsync
  WASM: ConfigurationManager.InitializeAsync
  WASM: Index.OnInitializedAsync
  WASM: Index.OnInitializedAsync config.Settings is null
  WASM: ConfigurationManager.Setting has been set: ApiBaseUrl https://localhost:44316 
  </code></pre>