rem
rem

Reputation: 17075

Ninject syntax for "Bind" with multiple arguments

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?

Upvotes: 23

Views: 11060

Answers (1)

Martin Owen
Martin Owen

Reputation: 5271

You can chain the calls to WithConstructorArgument:

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

Upvotes: 65

Related Questions