Reading Ninject WithConstructorArguments from Web.config

asp.net-mvc-4, c#, ninject, web-config

Solution

No, there is no such limitation of Ninject.

I suppose the problem is that `ConfigurationManager.AppSettings["DatabaseId"]` returns `string` and your `dbId` argument is of type `int` (or some other non-string type).

Try:

var databaseId = Int32.Parse(ConfigurationManager.AppSettings["DatabaseId"]); 
kernel.Bind<IStore>()
      .To<Store>()
      .WithConstructorArgument("dbId", databaseId);

Problem

I have the following RegisterServices function: ``` private static void RegisterServices(IKernel kernel) { kernel.Bind<ISearchRepository>().To<SearchRepository>(); kernel.Bind<ITagRepository>().To<TagRepository>(); kernel.Bind<IStore>().To<Store>() .WithConstructorArgument("dbId", ConfigurationManager.AppSettings["DatabaseId"]) } ``` Using breakpoints I can confirm that `ConfigurationManager` is correctly populating the value. However, when running I get the following exception when the kernel finishes binding: If I replace the `ConfigurationManager` reference with a constant the application runs fine. I don't want to lose the ability to configure Ninject through a config file, is this a limitation of Ninject?

Original source