This project is read-only.

Basic usage (ASP.NET MVC 2)

Configure the FluentFilters is very simple. All you need to do is set FluentFiltersControllerFactory as current controller factory and use FluentFiltersBuilder class for work with filters.
Firstly you need add a reference to FluentFilters.dll in your MVC project. After to edit your Global.asax file like below.
Note: If you use IoC container then read this.

Basic usage example:
// Global.asax.cs
using System.Web.Mvc;
using System.Web.Routing;
using FluentFilters;
using FluentFilters.Criteria;
using Website.Core.Filters;

namespace Website
{
    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        private static void RegisterFluentFilters()
        {
            // Register global filter
            FluentFiltersBuilder.Current.Add<BrowserDetectionFilter>(c => {
                c.Exclude(new ControllerFilterCriteria("Account"));
            });
        }

        private static void RegisterControllerFactory()
        {
            // Set controller factory
            ControllerBuilder.Current.SetControllerFactory(new FluentFiltersControllerFactory());
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            RegisterFluentFilters();

            RegisterControllerFactory();
        }
    }
}
Working example of application you can find in src\MVC2\Samples\FluentFilters.Samples.BasicUsage folder of source code.

Already have custom ActionInvoker?

If in your application you already have implemented custom controller factory, then you need set FluentFiltersActionInvoker as default as shown below.

Example of how to set FluentFiltersActionInvoker as default
var controller = icontroller as Controller;
if (controller != null)
{
    // Set custom ActionInvoker
    controller.ActionInvoker = new FluentFiltersActionInvoker(FluentFiltersBuilder.Current);
}

Last edited Jan 30, 2011 at 9:43 PM by banguit, version 9

Comments

No comments yet.