I have used Ninject in MVC Web application without any problem for injecting the business logic classes. But i want to inject the data access classes to the constructor of business logic classes. Logic layer is a class library and has no Program.cs class or entry point.
Data access class
public class DataAccessClass
{
public void Insert(Product product)
{
new SqlObj().Insert(Product);
}
}
Data access class interface
public Interface IDataAccessClass()
{
void Insert(Product product);
}
Business logic class
public class ProductLogic()
{
IDataAccessClass _dataAccessClass;
//DataAccessClass should be injected here using Ninject
public ProductLogic(IDataAccessClass dataAccessClass)
{
_dataAccessClass=dataAccessClass;
}
public InsertProduct(Product product)
{
_dataAccessClass.Insert(product);
}
}
This is what I need I have a 3 layer application and the layers are:
- Web: Presentation Layer (ASP.NET MVC) --> only sees BLL
- BLL: Business Logic Layer --> only sees DAL
- DAL: Data Access Layer
So the Web
layer doesn't know anything about my DAL
layer. I have repository interfaces and concrete classes in my DAL
, which are used in BLL
layer in business logic classes. The question is, in order to decouple DAL
and BLL
, how do I setup Ninject to inject my repository implementations to the BLL
layer?