Ninject syntax for "Bind" with multiple arguments

rem picture rem · Sep 10, 2010 · Viewed 10k times · Source

How I can use multiple parameters in Ninject syntax like following?

Bind<IMyRepository>()
.To<SqlMyRepository>()
.WithConstructorArgument("connectionString",
 ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString
 );

What if more than one parameter need to be passed?

Answer

Martin Owen picture Martin Owen · Sep 10, 2010

You can chain the calls to WithConstructorArgument:

Bind<IMyRepository>()
    .To<SqlMyRepository>()
    .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString)
    .WithConstructorArgument("timeout", 10000);