开发者

Ninject syntax for "Bind" with multiple arguments

开发者 https://www.devze.com 2023-01-15 10:00 出处:网络
How I can use multiple parameters in Ninject syntax like following? 开发者_运维问答Bind<IMyRepository>()

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?


You can chain the calls to WithConstructorArgument:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号