I am new to MVC and dependency injection. Please help me understand how this should work. I am using Ninject. Here is my code:
in the Global.asax file:
private void RegisterDependencyResolver()
{
var kernel = new StandardKernel();
kernel.Bind<IDbAccessLayer>().To<DAL>();
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
}
protected void Application_Start()
{
RegisterDependencyResolver();
}
The implementation of IDbAccessLayer is very simple:
public interface IDbAccessLayer
{
DataContext Data { get; }
IEnumerable<User> GetUsers();
}
Now in the controller I need to create a constructor that receives the IDbAccessLayer parameter. And it only works.
Now I do not know how to pass the DAL connection string. if I try to replace the DAL constructor with something that takes a parameter, this will not work. Throws an exception with the message Without constructor without parameters for this object
Agzam source
share