In my code, there is the registration of two different services with the same interface as this:
services.AddSingleton<IServiceResolver, ServiceResolver>();
services.AddSingleton<IService, ServiceA>();
services.AddSingleton<IService, ServiceB>();
The ServiceResolver is used to pick the correct service based on some circumstances. The ServiceResolver itself has a constructor like this:
public ServiceResolver(IEnumerable<IService> idServices, ...)
So, any business logic related code should always use the service resolver to pick the correct service to use.
The Problem:
IService can be injected directly into business code and will then be always ServiceB since this was the last IService registered.
Is there a way to prevent injecting a single implementation of an interface that was registered multiple times?
I know that as long as you stick to just injecting IServiceResolver there will be no problem, but the code would be much safer to use if this simple thing could be prevented somehow.