How to use .net core dependency injection in multiprojects solution?
<p>I'm new to asp.net core.<br>
What I'm trying to do is to build multi projects solution and use dependency injection to pass interfaces between projects.<br>
What I know is that in ASP.NET core project we have <code>ConfigureServices</code> method in <code>startup.cs</code> file to register our interfaces and their implementations like this:  </p>

<pre><code> public void ConfigureServices(IServiceCollection services)
 {
   // Add framework services.
   services.AddMvc();
   services.AddTransient&lt;IMyInterface,MyImplementation&gt;();
   .....
 }
</code></pre>

<p>This is good if you have classes all in the same project, but what if I have multi projects ?<br>
Usually what I'll do is create separate project with installers (Windsor installers) to register the needed interfaces and their implementations.  </p>

<p>In .net core we can do this by creating static <code>ServiceCollection();</code> and get from it static <code>IServiceProvider</code> to use it any time to get any service you register:</p>

<pre><code>public static IServiceCollection _serviceCollection { get; private set; }
public static IServiceProvider serviceProvider { get; private set; }
public static RegisterationMethod() {
   _serviceCollection = new ServiceCollection();

   _serviceCollection.AddSingleton&lt;IMyInterface,MyImplementation&gt;();
   .....
   serviceProvider = _serviceCollection.BuildServiceProvider();
}

public T GetService&lt;T&gt;() where T : class
{
   return serviceProvider.GetService&lt;T&gt;();
}
</code></pre>

<p>Now we call <code>RegisterationMethod</code> from ower startup project and continue to develop as usual with always registering the services in this class.<br>
The problem in this approach is if I used it in ASP.NET core project I'll have two places to register the services, this one and the one in the <code>startup.cs</code> file which has <code>ConfigureServices(IServiceCollection services)</code> .<br>
You may say, </p>

<blockquote>
  <p>OK pass <code>IServiceCollection</code> you had in <code>ConfigureServices(IServiceCollection services)</code> to the <code>RegisterationMethod</code> you previously created, in this way you're using the same services collection that ASP.NET using.</p>
</blockquote>

<p>But in this way I'll be tight coupled to the dependency injection module of the <code>.net core</code>.  </p>

<p>Is there more clean way to do this ? or should I have replace the default DI with <code>Windsor</code> for example ?</p>