Unity with ASP.NET Core and MVC6 (Core)
<p><strong>Update 09.08.2018</strong><br>
Unity is being developed <a href="https://github.com/unitycontainer/container" rel="nofollow noreferrer">here</a> but I haven't had the time to test how it plays with the ASP.NET Core framework.</p>
<p><strong>Update 15.03.2018</strong><br>
This solution is for the specific problem of using ASP.NET Core v1 with Unity while using the .NET Framework 4.5.2 <b>NOT</b> the .NET Core Framework. I had to use this setup since I needed some .Net 4.5.2 DLLs but for anyone starting afresh I would not recommend this approach. Also Unity is not being developed any further (to my knowlage) so I would recommend using the Autofac Framework for new projects. See this <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection#replacing-the-default-services-container" rel="nofollow noreferrer">Post</a> for more info on how to do that.</p>
<p><strong>Intro</strong><br>
I am building a Web Application using ASP.NET with MVC. This Application depends on certain services (a WCF Service a Datastore service etc). Now to keep things nice and decoupled I want to use a DI (Dependecy Injection) Framework, specifically Unity.<br><br>
<strong>Initial Research</strong><br>
I found this <a href="http://www.global-webnet.com/blog/post/2015/08/24/Dependency-Injection-in-ASPNET-vNext-(adding-Unity-container).aspx" rel="nofollow noreferrer">blog post</a> but sadly its not working. The idea though is nice.<br> It basically says that you should not register all the services registered in the ServiceCollection into your own container, but rather reference the default ServiceProvider.<br> So. if something needs to be resolved the default ServiceProvider is called and in case it has no resolution the type will be resolved using your custom UnityContainer.<br>
<br>
<strong>The Problems</strong>
<br>
MVC always tries to resolve the Controller with the default ServiceProvider. <br>Also, I noticed that even if the Controller would get resolved correctly, I can never &quot;mix&quot; Dependencies. Now, if I want to use one of my Services but also an IOptions interface from ASP the class can never be resolved because not one of those two containers has resolutions for both types.
<br><br>
<strong>What I need</strong>
<br>
So to recap I need the following things:</p>
<ul>
<li>A setup where I dont need to copy ASP.NET Dependencies into my UnityContainer</li>
<li>A container which can resolve my MVC Controllers</li>
<li>A container which can resolve "mixed" Dependencies</li>
</ul>
<p><strong>EDIT:</strong><br>
So the question is how can I achieve these points ?</p>
<p><strong>Environment</strong>
<br>project.json:<br>
<a href="https://i.stack.imgur.com/OVg2F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OVg2F.png" alt="enter image description here" /></a></p>