I have set up ninject on my project in the global.asax file…
protected void Application_Start()
{
RegisterDependencyResolver();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
private void RegisterDependencyResolver()
{
var kernel = new StandardKernel();
kernel.Bind<PteDotNetCore.IBlogManager>().To<PteDotNetCore.BlogManager>();
DependencyResolver.SetResolver(new PteDotNet.Resolution.PteDotNetDependencyResolver(kernel));
}
I have a controller with 2 consturctors….
public CodeController()
{
}
public CodeController(IBlogManager injectedManager)
{
manager = injectedManager;
}
When I remove the line:
kernel.Bind<PteDotNetCore.IBlogManager>().To<PteDotNetCore.BlogManager>();
from the first block of code my defaul constructor is used when the line is added then the constructor which takes the interface is used.
Please can someone tell me what decisions are being made by MVC to select the constructor? Its not quite clear.
The decision is actually made by ninject. For constructor injection it selects the one with the most parameters, see the wiki for details on exactly how this works
https://github.com/ninject/ninject/wiki/Injection-Patterns/1e462388cee1887a4bb90067cf334d91604f7ea8