Install NInject with Nuget
Install-Package Ninject
You can create a method for registering objects. You need to register all the dependencies necessary to create the object.
public static void Register(IKernel kernel) { kernel.Bind<IDataAccessClass>().To<DataAccessClass>(); kernel.Bind<ProductLogic>().ToSelf(); }
Create a new instance of StandardKernel and call Register to register the objects.
To get an instance of an object, you simply call the Get<> method, and you get a new view of this object. There are other methods.
static void Main(string[] args) { var kernel = new StandardKernel(); Register(kernel);
To solve the problem, only the BLL sees the DAL , you can add a new project (class library) where you install NInject and create this Register method. You can reference this class library in a Web project and register objects.
The objects
public class Product { } public class DataAccessClass : IDataAccessClass { public void Insert(Product product) { } } public interface IDataAccessClass { void Insert(Product product); } public class ProductLogic { IDataAccessClass _dataAccessClass;
source share