I have the following code in my MVC application which works fine.
container.Register(Component.For<CountryServiceBase>()
.ImplementedBy<CountryService>()
.LifestylePerWebRequest());
Castle Windsor creates a component
CountryService / CountryServiceBase
My controller gets an instantiated object here :
public class MyController : MainController
{
public CountryServiceBase CountryService {get; set;} // instantiate by Ioc : OK
My problem is that I have a lot of classes to register. So using Castle Windsor I did the following :
container.Register(
Types
.FromAssemblyNamed("mynamespace")
.BasedOn(typeof(ServiceBase<>))
.WithService.Base()
.LifestylePerWebRequest());
Castle Windsor creates my components
CountryService / ServiceBase<Country>
CountryServiceBase / ServiceBase<Country>
But my MVC Application awaits a CountryService / CountryServiceBase and I don't know how to specify to Castle Windsor that it can match back CountryServiceBase to CountryService as both those classes (one of them being an abstract one) inherits ServiceBase
Is it even possible ?
Note : I posted a similar question but my investigation leads to a more accurate one so I deleted the old one.
You can use reflection to get all classes inheriting from your serviceBase. You can find a the way to do this here
Then you can implement the code above to instantiate all the services.