Ninject in a three-tiered application

I am creating a standard 3 tier application.

1 Console application for frontend

2 Business logic layer

3 data layer

The main purpose is to display some customer data from a database table.

I am trying to follow the directions in Dependency Injection in .NET with no console link to the data tier and none of the business tier to the data tier. Allows you to easily swap front and data layers if needed.

Let's say I have a service in the CustomerService business layer and it has a method GetCustomers()

the constructor CustomerService

takes a ICustomerRepository

so that

 public class CustomerService 
 {
     ICustomerRepository repository; 

     public CustomerService(ICustomerRepository repository) 
     {
        this.repository = repository;
     }

     public ICollection<Customer> GetCustomers() 
     {
         return repository.GetCustomers();
     }
}

      

On the data layer I have

public class CustomerRepository : BLL.ICustomerRepository 
{
    public ICollection<Customer> GetCustomers()
    {
         // get the customers from the db 
         return customers;
    }
}

      

In a console application, I want to invoke the creation of a CustomerService object using Ninject to execute the ICustomerRepository dependency.

 class DIModule : NinjectModule
 {
    public override void Load()
    {
        Bind<>(ICustomerRepository).To<??????????????>()
    }
 }

      

How can I bind data layers to the CustomerRepository layer? Do I need to add a link from the console app to the data layer for this to work? What am I doing wrong?

0


source to share


1 answer


Bind<ICustomerRepository>().To<CustomerRepository>();

      



+1


source







All Articles