I have a generic interface IDataService<T>
and its default implementation DataService<T>
. Then, some types have their particular service interface, which implement also IDataService
, for example:
public interface IClientService : IDataService<Client>
{
void SomeProcess();
}
public class ClientService : DataService<Client>, IClientService
{
public override SomeDataServiceMethodOverride();
public void SomeProcess();
}
As you can see, ClientService
is a specialised IDataService<Client>
which extends the functionality of DataService<Client>
and also implements another interface.
What I would like is that when I ask to StructureMap for an IDataService<Client>
it gives me a ClientService
, but when I ask for a IDataService<OtherEntity>
just falls back to the default implementation DataService<OtherEntity>
. What I had until now in my StructureMap configuration was:
Scan(
scan => {
scan.AssemblyContainingType<IClientService>();
scan.AssemblyContainingType<ClientService>();
scan.WithDefaultConventions();
});
For(typeof(IDataService<>)).Use(typeof(DataService<>));
but the problem was that it didn't instantiate a ClientService
when asking for IDataService<Client>
, but a DataService<Client>
. Now I changed the last line to:
For(typeof(IDataService<OtherEntity>)).Use(typeof(DataService<OtherEntity>));
But then I have to do that for any entity which does not have a concrete service implementation. How can I do that automatically?