views:

233

answers:

2

Configuration:


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;
        }
**Error:**
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. 
A: 

You need some kind of initalization of your application, where you can register all your components, you should try not have to have any of your classes from using the container directly.

Your problem seems to be because, while you have registered the ICustomerService, it uses ICustomerRepository which you have not registered, so cannot create the ICustomerService for you.

Michael Baldry
A: 

I forgot to add the repository component:

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

It all work now..

Fleents

related questions