Dependency injection with AutoFac in ASP.NET 5
October 31, 2015 by Anuraj
aspnet5 Dependency injection codeproject autofac
ASP.NET5 comes with inbuilt dependency injection framework. This post is about using Autofac DI framework instead the in built DI framework. You can find more details about ASP.NET5 DI Framework in ASP.NET5 DependencyInjection respository. And you can find more details about Autofac in Autofac documentation
First you need to refererence the Autofac related assemblies in the project.json file
I am using the autofac getting started example interface and implementation.
And here is the implementation.
Then you need to regsiter types with autofac container in your startup file ConfigureServices() method. You also need to modify the signature of the method as well.
Now you have completed the configuration. You can use the IOutput in controller constructor like this.
Happy Programming
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub