forked from ninject/Ninject.Web.Mvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Filter configurations
remogloor edited this page Mar 30, 2012
·
6 revisions
In the previous examples you have already seen that a filter can be configured by adding one or more With statements to the binding configuration. But some times it is necessary to have different configurations for different actions. In this case it’s possible to get the configuration value from an attribute of the action or controller. The next example shows all new With overloads that come with the MVC3 extension.
[Log(LogLevel = Level.Debug)] void Index() {} this.BindFilter<LogFilter>(FilterScope.Controller, 0) .WhenControllerHas<LogAttribute>() .WithConstructorArgumentFromControllerAttribute<LogAttribute>( "logLevel", attribute => attribute.LogLevel); // For property injection WithPropertyValueFromControllerAttribute instead this.BindFilter<LogFilter>(FilterScope.Action, 0) .WhenActionHas<LogAttribute>() .WithConstructorArgumentFromActionAttribute<LogAttribute>( "logLevel", attribute => attribute.LogLevel); // For property injection WithPropertyValueFromActionAttribute instead this.BindFilter<LogFilter>(FilterScope.Action, 0) .WhenActionHas<LogAttribute>() .WithConstructorArgument(( "logLevel", (context, controllerContext, actionDescriptor) => actionDescriptor.ActionName == "Index" ? Level.Info : Level.Warn);
Further Information on this topic: