How to link settings with Web.config using Ninject in ASP.NET MVC 4?

I have Repositoryone that accepts Providerwhich needs to pass an object to ProviderCredentials. An object ProviderCredentialsis a class, but its values ​​are known only at runtime because they live in the Web.config section <applicationSettings />.

How can I extract values ​​from Web.config, build an object ProviderCredentialsand enter it in Providerusing Ninject? Not sure if it matters, but classes Providerand ProviderCredentialslive in a separate project than MVC project in the same solution.

+4
source share
1 answer

ProviderCredentials factory, ​​ :

kernel.Bind<ProviderCredentials>()
      .ToMethod(context =>
             new ProviderCredentials(ConfigurationManager.AppSettings["Foo"])
      );
+5

All Articles