title: Orleans direct client in ASP.NET Core project
body: <p>I am currently looking into Orleans as a backend for Asp.net core web api project, and was wondering if anyone has any experience with its new feature - "direct client".  The orleans docs say "<em>it allows co-hosting a client and silo in a way that let the client communicate more efficiently with not just the silo it's attached to, but the entire cluster</em>", and I am aware that you can code something like this (and it works just fine in a console app):</p>
  
  <pre><code>var silo = new SiloHostBuilder()
                 .UseLocalhostClustering()
                 .EnableDirectClient()
                 .Build();
  
  await silo.StartAsync();
  
  var client = silo.Services.GetRequiredService&lt;IClusterClient&gt;();
  </code></pre>
  
  <p>I am struggling trying to figure out where to put this type of code in an asp.net project that has its own webhost builder in "Main" (should it go to Startup class in "ConfigureServices"?).  In the end, we are aiming for a separate client/server setup, but for faster development it would be useful to play with a simple setup, which direct client appears to allow for. Any pointers to resources and/or sample solutions containing direct client with asp.net core would be appreciated.  Thanks.</p>
  
  <p><strong>EDIT</strong>: Here's the code that kinda works for me now, but I am not happy with he way the DI is set up</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static async Task Main(string[] args)
          {
  
              var silo = new SiloHostBuilder()
                      .UseLocalhostClustering()
                      .ConfigureServices(services =&gt;
                      {
                          services.AddDbContext&lt;UserDbSet&gt;(o =&gt;  o.UseSqlite("Data Source=UserTest.db"));
                          services.AddMediatR(typeof(Startup).Assembly);
                      })
                      .EnableDirectClient()
                      .Build();
  
              await silo.StartAsync();
  
              var client = silo.Services.GetRequiredService&lt;IClusterClient&gt;();
  
              await WebHost.CreateDefaultBuilder(args)
                          .UseConfiguration(new ConfigurationBuilder()
                              .AddCommandLine(args)
                              .Build())
                          .ConfigureServices(services =&gt;
                              services
                               .AddSingleton&lt;IGrainFactory&gt;(client)
                               .AddSingleton&lt;IClusterClient&gt;(client))
                          .UseStartup&lt;Startup&gt;()
                          .Build()
                          .RunAsync();
          }
  </code></pre>
  
  <p>If I put registration of the <code>DbContext</code> and <code>Mediatr</code> in the <code>StartUp</code> class, grain code fails with an exception indicating failure to instantiate the required dependencies.  Maybe I am doing something wrong when setting up the <code>Webhost</code>?</p>