2009-11-22 4 views
0

Configuration:Windsor Castle IoC: Comment Initialiser Service et couche référentiel


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

Controller:


     private ICustomerService _service; 

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

Service Layer:


     private ICustomerRepository _repository; 

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

Erreur:

 
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. 

Répondre

0

Vous avez besoin d'une sorte de initalization de votre application, vous pouvez enregistrer tous vos composants, vous devriez essayer de n'avoir un de vos cours d'utilisation du conteneur directement. Votre problème semble être dû au fait que, bien que vous ayez enregistré ICustomerService, il utilise ICustomerRepository que vous n'avez pas enregistré, donc vous ne pouvez pas créer ICustomerService pour vous.

0

J'ai oublié d'ajouter le composant référentiel:

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

Tout travail maintenant ..

Questions connexes