How far does Dependency Injection reach?

Posted by Baddie on Stack Overflow See other posts from Stack Overflow or by Baddie
Published on 2010-03-14T01:12:40Z Indexed on 2010/03/14 1:15 UTC
Read the original article Hit count: 397

My web app solution consists of 3 projects:

  1. Web App (ASP.NET MVC)
  2. Business Logic Layer (Class Library)
  3. Database Layer (Entity Framework)

I want to use Ninject to manage the lifetime of the DataContext generated by the Entity Framework in the Database Layer.

The Business Logic layer consists of classes which reference repositories (located in the database layer) and my ASP.NET MVC app references the business logic layer's service classes to run code. Each repository creates an instance of the MyDataContext object from the Entity Framework

Repository

public class MyRepository
{
     private MyDataContext db;
     public MyRepository
     {
        this.db = new MyDataContext();
     }

     // methods
}

Business Logic Classes

public class BizLogicClass
{
     private MyRepository repos;
     public MyRepository
     {
          this.repos = new MyRepository();
     }

     // do stuff with the repos
}

Will Ninject handle the lifetime of MyDataContext despite the lengthy dependency chain from the Web App to the Data Layer?

© Stack Overflow or respective owner

Related posts about ninject

Related posts about dependency-injection