GP
unread,Mar 11, 2011, 9:37:03 AM3/11/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ninject
I have a question regarding conditional bindings for filters in
Ninject.Web.Mvc. Is it possible to use conditional bindings to bind
the same filter to several different conditions? So in the example
below I want it to apply MyActionFilter to the MyMethod() method once
for each of the tagged attributes:
class KeyStore
{
public static Aap { // ... }
public static Noot { // ... }
public static Mies { // ... }
// ...
}
class AapAttribute : Attribute { }
// ...
class MyActionFilter : IActionFilter
{
public MyActionFilter (string key)
{
// ...
}
// ...
}
class Bindings : NinjectModule
{
public override void Load()
{
// ...
this.BindFilter<MyActionFilter>(FilterScope.Action, 0)
.WhenActionHas<AapAttribute>()
.WithConstructorArgument("key", context => KeyStore.Aap);
this.BindFilter<MyActionFilter>(FilterScope.Action, 0)
.WhenActionHas<NootAttribute>()
.WithConstructorArgument("key", context => KeyStore.Noot);
this.BindFilter<MyActionFilter>(FilterScope.Action, 0)
.WhenActionHas<MiesAttribute>()
.WithConstructorArgument("key", context => KeyStore.Mies);
// ...
}
}
[Aap, Noot, Mies]
public ActionResult MyMethod()
{
// ...
}
I tried this but I get an ActivationException stating that there are
more than one matching bindings available.
Thx!