Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Ninject dynamically to connection to different databases
    primarykey
    data
    text
    <p>I have an MVC application using Ninject to connect to a single database. Now I need to support multiple databases. Currently, my global.asax.cs file has the following definition for ninject:</p> <pre><code> protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); //Using DI for controllers - use the Ninject custom controller factor ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); // Repository config is defined in ninject controller } </code></pre> <p>And here is what my Ninject controller class looks like:</p> <pre><code>public class NinjectControllerFactory : DefaultControllerFactory { private IKernel kernel = new StandardKernel(new EriskServices()); protected override IController GetControllerInstance(RequestContext context, Type controllerType) { if (controllerType == null) return null; return (IController)kernel.Get(controllerType); } private class EriskServices : NinjectModule { public override void Load() { Bind&lt;IRisksRepository&gt;().To&lt;MySql_RisksRepository&gt;() .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["mydb1"].ConnectionString); } } } </code></pre> <p>I also have a login page that handles user authentication. It is done through LDAP and does not require database connection.</p> <p>My question is: Can I bind the ninject connectionString after the user authentication login page? The user would have a dropdown list for database they want to connect to, for example "mydb1" or "mydb2" or "mydb3". Each connection string would be defined in the web.config file.</p> <p>Please help! Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload