2013-07-03 3 views
0

나는 사용자가 자신을 등록 할 수있는 등록을 한 후 Home Page로 이동합니다. MVC3에서이 작업을 수행하지만 3Tier로 변환합니다. 프레 젠 테이션 및 DAL 만든 및 모델 폴더 및 DbContext뿐만 아니라 추가 및 Presentation.And 모델에서 삭제 된 BLL 어디에 내가 삽입, 삭제 및 업데이트에 대한 모든 논리를 쓰고 싶은 만들고 액세스 할 그것은 내 프레젠테이션에있는 내 컨트롤러에 있습니다. 어떻게해야합니까? 제발 이것에 가이드!프레 젠 테이션 레이어에서 BLL의 기능에 액세스

+0

BLL에는 삽입, 삭제, 업데이트 할 수 없습니다. 사실 내가 본 것에서는 비즈니스 계층이 정말로 필요하지 않습니다. 컨트롤러에서 DAL을 직접 사용하기 만하면됩니다. – MikeSW

답변

0

전체 솔루션을 다시 작성 해달라고 요청한 것처럼 보입니까?

온라인 시작 키트가 많으므로이를 수행하는 방법에 대한 힌트를 얻을 수 있습니다. 동일한 결과를 얻는 데는 여러 가지 방법이 있습니다. 내가하는 일에 대한 간단한 개요를 알려 드리겠습니다.

고객에 대한 참조를 작성하기 위해 솔루션에 맞게 수정할 수 있습니다.

나는 MyProject.DomainModel이라는 솔루션을 가지고 있습니다. 내가 MyProject.EntityFramework라는 프로젝트를

public class Customer 
{ 
    public int Id { get; set; } 

    public string FirstName { get; set; } 

    public string LastName { get; set; } 

    public int Age { get; set; } 
} 

:이 프로젝트에서 내 고객 클래스가 있습니다. 여기에 모든 저장소 클래스가 있습니다. 고객 저장소 방법의 예 : 다음 다른 프로젝트가 MyProject.Services라고 한

public IEnumerable<Customer> FindAll() 
{ 
    return DatabaseContext.Customers; 
} 

. 고객 서비스가 고객 저장소를 호출합니다. 서비스 계층은 필요 없지만 일부 논리가 필요하거나 다른 리포지토리를 호출해야 할 때 서비스 계층을 사용합니다.

public interface ICustomerService 
{ 
    IEnumerable<Customer> FindAll(); 
} 

public class CustomerService : ICustomerService 
{ 
    private readonly ICustomerRepository customerRepository; 

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

    public IEnumerable<Customer> FindAll() 
    { 
      return customerRepository.FindAll(); 
    } 
} 

당신은 CustomerService를 생성자가 ICustomerRepository의 인스턴스를받는 것을 볼 수 있습니다 : 이것은 내가 서비스 계층에서 저장소 메서드를 호출 할 방법이다. 이것은 Autofac과 같은 의존성 주입 프레임 워크에 의해 처리됩니다.

public class CustomerController : Controller 
{ 
    private readonly ICustomerService customerService; 

    public CustomerController(ICustomerService customerService) 
    { 
      this.customerService = customerService; 
    } 

    public ActionResult List() 
    { 
      IEnumerable<Customer> customers = customerService.FindAll(); 

      return View(customers); 
    } 
} 

이보다 훨씬 더있다 :

는 컨트롤러에서 모든 고객을 표시하는 목록보기가있는 목록 작업 방법이있을 것이다. 시동기 키트를 온라인으로 다운로드하고 올바른 경로로 연결하기 위해 작업해야합니다. 제가 제시 한 것은 일반적인 개요입니다.

이 정보가 도움이되기를 바랍니다.

관련 문제