Design Object POCO Objects / DAL Access

I would like to implement a typical three-layer architecture. My current approach is as follows

  • DAL - with EF 4.0 and repositories for each of my objects. access via interfaces
  • I was thinking about using POCO objects. My first question is: where should I put these files? In the assembly referenced by all other projects?
  • BLL - How to get data from DAL to BLL, and then finally to the GUI This is a good way if I had a whole group of manager classes such as CustomerManager in BLL. These classes will access the appropriate repository in the BLL, and then pass the objects to the GUI

Or do you think it is better to place the repository in BLL and access them directly from my buttoneventhandler operator?

Hope you can bring the light into the dark.

+5
source share
3 answers

We have repositions in DAL. BLL refers to repositories through an interface - therefore repositories are tied to DAL but disconnected from BLL. I do not know why the repositories could not be directly in the BLL. We got them in DAL, since we did not put ANY logic in them. Then we have the β€œManagers” in the BLL who migrate the repositories and process the entity-specific logic.

FWIW Repository(Of IEntity) - . POCO IEntity, Id, CreatedDate .., . , - CreatedDate CreateInstance(), ModifiedDate , Modified

- DAL , BLL. , DAL, DAL- . BLL . DAL, .

BLL, . , , -, DAL BLL ( , ) , / , .

, , - ,

+6

:

Company.Project.Domain.Model      (POCOs)
Company.Project.Business.Services (BLL)
Company.Project.Data.Repositories (Repository)
Company.Project.Web               (Presentation)
  • POCO . .
  • BLL , - . ICollection<T> T. ( IRepository<T> ) POCOs.
  • - , IRepository<T>, . , , .. IQueryable. POCO's, BLL.
  • - . POCOs BLL.

- , , ( DI), .

Mock Repositories, DI Entity Framework, BLL DI.

UI β†’ DB:

// "Company.Project.Web.ProductsController.cs"
public class ProductsController : BaseController
{
   private IProductService _productService;

   public ProductsController(IProductService productService)
   {
      this._productService = productService; // DI makes me happy :)
   }

   public ActionResult GetOrdersForProduct(Product product)
   {
      var orders = _productService.GetOrders(product);
      return View(orders);
   }
}

// "Company.Project.Business.Services.ProductService.cs"
public class ProductService : IProductService
{
   private IRepository<Product> _productRepository;

   public ProductService (IRepository<Product> productRepository)
   {
      this._productRepository = productRepository; // DI makes me happy :)
   }

   public ICollection<Orders> GetOrdersForProduct(Product product)
   {
      return _productRepository
                .Find()
                .ForProduct(product) // IQueryable<Product> pipe/extension filter
                .ToList();
   }
}

// "Company.Project.Data.Repositories.GenericRepository.cs
public class GenericRepository<T> : IRepository<T> where T : class
{
   private IObjectSet<T> _objectSet;

   public GenericRepository(IUnitOfWork unitOfWork)
   {
      CurrentContext = unitOfWork as SqlServerUnitOfWork;
   }

   public IQueryable<T> Find()
   {
      return CurrentContext.GetEntitySet<T>();
   }

   protected SqlServerUnitOfWork CurrentContext { get; private set; }

   protected IObjectSet<T> CurrentEntitySet
   {
      // some plularization smarts in "SqlServerUnitofWork.cs", to dynamically pull
      // back entity set based on T.
      get { return _objectSet ?? (_objectSet = CurrentContext.GetEntitySet<T>()); }
   }
}

, DI.

+3

, POCOs . . POCO , . .

Your BLL can be a classic Facade or Service Locator. This project will massage your data and apply any relevant business rules before passing it to the user interface. It will also be responsible for checking the data coming from the user interface before sending it to the DAL.

+1
source

All Articles