سؤال

My project is done using portable areas, I’m using ninject for DI, I’m injecting a class that is in other assembly, so I have this code in the areaRegistraction:

DependencyResolver.Current.GetService<IModuleManager>().Add(this.module);  
IKernel kernel = DependencyResolver.Current.GetService<IKernel>();  
kernel.Bind<IConfigurationRepository>().To<ConfigurationRepository>();  

In my constructor I have this code:

public RequestController(IconfigurationRepository configurationRepository)
{
    this.configurationRepository= configurationRepository;
}

But by some reason configurationRepository is null

But if I put:

public RequestController()
{
   this.configurationRepository = ((StandardKernel)DependencyResolver.Current.GetService<IKernel>()).GetAll<IConfigurationRepository>().First();
}

It works fine. What is the different between them?

Any clue will be really appreciated.

هل كانت مفيدة؟

المحلول

The second implementation will work if several IConfigurationRepository are registered but the first one will fail in this case.

What's the exception in the first case? What happens if you use Single instead of First in the second case?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top