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

View: 2446|Reply: 0

[ASP.NET] ASP.NET MVC uses Autofac to add global filters

[Copy link]
Posted on 5/5/2024 7:15:08 PM | | | |
Requirements: Add a global filter ASP.NET MVC, the filter constructor has dependencies, and you need to inject related services to test using the newly created web project of .NET Framework version 4.8.

First, reference the Autofac related dependency package as follows:


Create a new IAuthenticationFilter authentication filter for testing, the code is as follows:

Open the Global.asax.cs and modify it as follows:

DependencyResolver is an important component in MVC, as the name suggests, it is responsible for the resolution of dependency objects, and it can be said that it is an IOC container used inside the MVC framework. Many objects are created through MVC, and we may not use it directly, but if you are using Unity, Autofac, or looking at some open source projects, you will always see it.

Start debugging and test as shown below:



(End)





Previous:The frontend uses spark-md5 to calculate the file MD5 value
Next:ASP.NET Core (27) Performance optimization PurgeCSS to remove unused code
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