I use Castle Windsor as my IoC container. I have an application that has a structure similar to the following:
IEmployeeService
IContractHoursService
...
EmployeeService : MyApp.Services.IEmployeeService
ContractHoursService : MyApp.Services.IContractHoursService
...
I use the XML configuration at the moment, and every time I add a new IService/Service pair, I have to add a new component to the XML configuration file. I want to switch all this over to the fluent registration API but haven't worked out exactly the right recipe to do what I want yet.
Can anyone help? The lifestyles will all be singleton
.
Many thanks in advance.
With AllTypes
you can easily do this:
Registering components one-by-one can be very repetitive job. Also remembering to register each new type you add can quickly lead to frustration. Fortunately, you don't have to do it, at least always. By using AllTypes entry class you can perform group registration of types based on some specified characteristics you specify.
I think your registration would look like:
AllTypes.FromAssembly(typeof(EmployeeService).Assembly)
.BasedOn<IEmployeeService>()
.LifeStyle.Singleton
If you implement a base type, like IService
on your interfaces, you can register them all at once using the following construct:
AllTypes.FromAssembly(typeof(EmployeeService).Assembly)
.BasedOn<IService>()
.WithService.FromInterface()
.LifeStyle.Singleton
For more examples, see the article. This has a very good description on what the possibilities are.