带有多个参数的“Bind”的Ninject语法

时间:2010-09-10 17:16:37

标签: c# asp.net-mvc ninject

如何在Ninject语法中使用多个参数,如下所示?

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

如果需要传递多个参数怎么办?

1 个答案:

答案 0 :(得分:60)

您可以将来电链接到WithConstructorArgument

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