2009-11-22 2 views
0

구성 :성 윈저 IOC의 : 서비스 및 저장소 레이어를 초기화하는 방법


component id="customerService" service="MyApp.ServiceLayer.ICustomerService`1[[MyApp.DataAccess.Customer, MyApp.DataAccess]], MyApp.ServiceLayer" type="MyApp.ServiceLayer.CustomerService, MyApp.ServiceLayer" 

컨트롤러 :


     private ICustomerService _service; 

     public CustomerController() 
     { 
      WindsorContainer container = new WindsorContainer(new XmlInterpreter()); 
      _service = container.Resolve>("customerService"); 
     } 

서비스 레이어 :


     private ICustomerRepository _repository; 

     public CustomerService(ICustomerRepository repository) 
     { 
      _repository = repository; 
     } 

오류 :

 
Can't create component 'customerService' as it has dependencies to be satisfied. 
customerService is waiting for the following dependencies: 

Services: 
- MyApp.Repository.ICustomerRepository`1[[MyApp.DataAccess.Customer, MyApp.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] which was not registered. 

답변

0

당신은 당신의 모든 구성 요소를 등록 할 수 있습니다 응용 프로그램의 initalization, 어떤 종류의 필요, 직접 컨테이너를 사용하는 수업 중 하나를 할 필요는 없습니다 시도해야합니다.

ICustomerService를 등록하는 동안 등록되지 않은 ICustomerRepository가 사용되므로 ICustomerService를 만들 수 없기 때문에 문제가 발생한 것 같습니다. ..

<component id="customerRepository" service="MyApp.Repository.ICustomerRepository`1[[MyApp.DataAccess.Customer, MyApp.DataAccess]], MyApp.Repository" type="MyApp.Repository.CustomerRepository, MyApp.Repository"/> 

그것은 이제 모든 작업 :

0

나는 저장소 구성 요소를 추가하는 것을 잊었다