ninject / Ninject.Web.Mvc

extension for ninject providing integration with ASP.NET MVC
http://ninject.org/
Other
238 stars 85 forks source link

Parameter name to WithConstructorArgumentFromControllerAttribute is not enforced #42

Open mikesmithphl opened 8 years ago

mikesmithphl commented 8 years ago

Given the following code

this.BindFilter<FooFilter>(FilterScope.Controller, order: 0)
    .WhenControllerHas<FooAttribute>()
    .WithConstructorArgumentFromControllerAttribute<FooAttribute>(parameterName, someLambda);

I've found that the parameterName passed in must not be null or empty, but as long as a type matches, it will succeed. My expectation was that it would fail to bind if it couldn't find a parameter with the proper name AND type provided. Ninject seems to prefer Constructors with more dependencies, so it's possible you could attempt to override a parameter of one constructor with less parameters but will instead override the other that may contain a non-matching name.

For example:

public class FooFilter : IFooFilter
{
    public FooFilter(IFoo f) { .. }
    public FooFilter(IFoo foo, IBar bar) { .. }
}

Specifying a constructor parameter name of "f" will still prefer the latter constructor. The parameter name seems to be ignored.