ASP. net mvc exploration path-do not want to write the same fitlerattribute (lower) on multiple actions)

Source: Internet
Author: User
It has been several days since the previous analysis. First, because there are few people who are concerned about it, and second, they are porting ASP. net mvc 3.0 RC, so they are not in a rush.
Today, it took some time to download the demo. I hope you can give some comments.

We know that in ASP. net MVC 3.0 provides a globalfilters (including a globalfiltercollection) for us to register a global filter, but it is not flexible enough-in fact, it cannot be said that, because its purpose is to provide a global filter registrar. Including globalfilters, Asp. net MVC 3.0 RC adds about 10 interfaces, classes, or enumerations to enhance the filter compared to 2.0 RTM, and adds two constructors for controlleractioninvoker to work with it. In particular, the newly added filterattributefilterprovider and globalfiltercollection ifilterprovider enable the filter to be cached, which improves the performance compared with ASP. net mvc 2.0. At present, there are only a few words in the White Paper to mention this.

In today's demo, I implemented a filterregistryfilterprovider: ifilterprovider. Its advantage over globalfilters is that it provides a scalable and configurable filter injection method:

1. Discard the method of marking attribute on the controller and action to implement filter injection and obtain it through reflection when needed. Although I don't feel bad about reflection, since it can improve performance a little bit, why not. In addition, the filter is injected outside the controller, and the coupling with the controller is also removed. Just like globalfilters, you do not need to inject data using attribute tags.
2. If there are acontroller, bcontroller, cdefg... and so on, you can specify to inject filter only to some controllers. When the requirement changes, the injection can be easily canceled. As stated in the first article, there is no need to change the controllers we have compiled.
3. If Actiona of acontroller and actionc of bcontroller need a filter, precise injection can be performed.
4. Inject actions under a certain or certain route
5. A routevalue can be injected into a filter for a request whose value is equal to (not equal to or inclusive. 6. A datatoken request that is equal to (not equal to, contains) A value can be injected into a filter (for example, some areas can be injected ).

7. Multiple conditions are combined for judgment to meet advanced requirements.
8. during system initialization, the filter instance can be cached like globalfilters to avoid unnecessary duplication of creation and destruction processes (thanks to the hetian Reminder)
9. You can easily extend the injection conditions.

Let's talk about it later. Go to the demo. In addition, the demo requires ASP. net mvc 3.0 RC or a later version, and. NET Framework 4.

: Filterregistrydemo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.