title: How to call some async code in an ASP.NET application_start
body: <p>In our application_startup, we seed up our database with some fake data, if no data exists.</p>
  <p>To do this, we're using the <code>Async</code> methods to store the data. Great. Only problem is, we're not sure how to do this in the <code>application_startup</code> because that's not an async method.</p>
  <p>I've spent soooo much time trying to understand @StevenCleary's tutorials and I'm always getting deadlocks. I totally <a href="http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html" rel="noreferrer">grok what he consistently says</a>:</p>
  <blockquote>
  <p>As a general rule, you should use &quot;async all the way down&quot;; that is, don't block on async code</p>
  </blockquote>
  <p>but I just don't get how I can do that, in this case :(</p>
  <p>Lets imagine this is the code I'm trying to play with...</p>
  <pre><code>protected void Application_Start()
  {
      var someFakeData = LoadSomeFakeData();
      var documentStore = new DocumentStore();
      await documentStore.InitializeAsync(someFakeData);
  
      ...
  
      // Registers this database as a singleton.
      Container.Register(documentStore);
  }
  </code></pre>
  <p>and later on .. some code that uses this <code>documentStore</code>. It is injected via construction injection ...</p>
  <pre><code>public SomeController(IDocumentStore documentStore)
  {
      _documentStore = documentStore;
  }
  
  public ViewModel GetFoos()
  {
      using (var session = _documentStore.OpenSession())
      {
          ... db code goes in here ... 
      }
  }
  </code></pre>
  <h3>Clarification</h3>
  <p>I'm <em>not</em> trying to do some async code in here. I'm actually trying to call this async method, <em>synchronously</em>. Sure, i loose the benefits of async blah blah de blah.. but i'm happy with that. This is start up and I'm happy to block on startup.</p>