You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this.Bind<IBar>().ToMethod(ctx => new Bar()).WhenTargetHas<BarAttribute>();
this.Bind<IBar>().ToMethod(ctx => new Bar2());
When I inject IBar, Ninject correctly injects new Bar() when there's BarAttribute and
injects new Bar2() without BarAttribute.
For instance,
public class BarController
{
public BarController([Bar]IBar bar) {} // injects new Bar()
}
public class Bar2Controller
{
public Bar2Controller(IBar bar) {} // injects new Bar2()
}
But using BindHttpFilter, this "chain" behavior is different..
this.BindHttpFilter<FooAttribute>(FilterScope.Action)
.WhenActionMethodHas<AllowAnonymousAttribute>()
.WithConstructorArgument("foo", (object)null);
this.BindHttpFilter<FooAttribute>(FilterScope.Action);
public class FooController
{
[AllowAnonymous]
public Method() {}
}
public class FooAttribute : AuthorizeAttribute
{
public FooAttribute(IDependency dependency) {}
}
When I request /foo/method, Ninject calls FooAttribute twice and injects null (using first binding) as expected, then instantiates FooAttribute again with IDependency binding.
What I expected was Ninject.Webapi chain the conditions and solve at the first match, as it does with normal Bind<>.
To solve my need (inject some paremeter when action is decorated with [AllowAnonymous], and another parameter when action isn't decorated with [AllowAnonymous]), I need to create mutual exclusive conditions which is a bad to maintain these two behaviors with Ninject Bind<> and Ninject.Web.WebApi BindHttpFilter<>:
I have these bindings in NinjectModule:
When I inject
IBar
,Ninject
correctly injectsnew Bar()
when there'sBarAttribute
andinjects
new Bar2()
withoutBarAttribute
.For instance,
But using
BindHttpFilter
, this "chain" behavior is different..When I request
/foo/method
, Ninject calls FooAttribute twice and injects null (using first binding) as expected, then instantiates FooAttribute again with IDependency binding.What I expected was Ninject.Webapi chain the conditions and solve at the first match, as it does with normal Bind<>.
To solve my need (inject some paremeter when action is decorated with
[AllowAnonymous]
, and another parameter when action isn't decorated with[AllowAnonymous]
), I need to create mutual exclusive conditions which is a bad to maintain these two behaviors with Ninject Bind<> and Ninject.Web.WebApi BindHttpFilter<>:What do you think ?
The text was updated successfully, but these errors were encountered: