How does one register multiple data providers for certain interface with IOC (I use Ninject but you can answer in general), for instance ISettingsRepository
is implemented by JsonSettingsProvider
and XmlSettingsProvider
.
I am migrating my data (settings in this case) from XML to JSON and need to use both of them at the same time in application (not chosing between one of them but both at the same time at runtime). So I need XML based provider to read in what was serialized and use JSON provider to serialize it back as JSON.
public class WebSettings
{
[Inject]
private ISettingsRepository _repository;
private void Load()
{
_repository = DependencyResolver.Current
.GetService<ISettingsRepository>();
...
Now I'd have registration such as:
kernel.Bind<ISettingsRepository>()
.To<XmlSettingsProvider>()
.InRequestScope();
Hopefully you understand what I mean.