This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18489|Reply: 2

[ASP.NET] mvc Controller Autofac attribute injected into the controller

[Copy link]
Posted on 4/9/2017 1:14:35 PM | | | |


The most commonly used is the automatic injection of constructors, the following code:



How to automatically inject interface attributes in the controller? The code is as follows:




Controller:



Application_Start Startup Method:



In fact, it is set here: builder. RegisterType<HomeController>(). As<BaseController>(). PropertiesAutowired()

Interface:



Interface Implementation Class:



Note:

The attribute must be set to public!! protected cannot be injected automatically!!




Previous:EF ORM Development and Use Series Tutorials
Next:The CREATE DATABASE statement is not allowed within a multi-statement transaction
 Landlord| Posted on 4/18/2017 2:45:31 PM |
nuget Install-Package Autofac.Mvc4
Install-Package Autofac.Extras.DynamicProxy2
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com