Fluent-API to add ActionFilters to Controllers – ASP.NET MVC Part 2

I’m working with my Fluent-API for adding Action Filters to Controllers and Action Methods. In my previous post, I created a new instance of each Action Filter and add it to an Action Method or Controller. Based on how the Action Filters are often implemented they don’t or shouldn’t keep any state, so in that case I don’t need to create a new instance of the same Action Filter with the same configuration for each Action Method I want to add it to. I also want to have an option to have a better overview of which Action Filter is added to which Controllers and Action Methods. I have added to methods, AddFilterToControllers and AddFilterToActions:

            .AddFilterToActions(new HandleErrorAttribute(),
                                c=> c.About(),
                                c=> c.Index());
            .AddFilterToActions(new OutOfMemoryException(),
                                c=> c.About());
             .AddFilterToActions(new HandleErrorAttribute() { ... },
                                c=> c.MyMethod());

The code is not yet available due to some more changes and testing.

No Comments