开发者

ConstructorArguments without magic strings

开发者 https://www.devze.com 2023-03-19 16:00 出处:网络
If I want to specify a constructor argument I need to specify the argument name as string. Unfortunately, this is no开发者_StackOverflowt very refactoring friendly. Is there any way to get around this

If I want to specify a constructor argument I need to specify the argument name as string. Unfortunately, this is no开发者_StackOverflowt very refactoring friendly. Is there any way to get around this limitation?


See http://www.planetgeek.ch/2011/05/28/ninject-constructor-selection-preview/ . The next release of Ninject will support to type safely define constructor arguments.


Do:

string s = "my string"
kernel.Bind<IMyInterface>().ToConstructor(x => new MyObject(s));

where MyObject implements IMyInterface.

0

精彩评论

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

关注公众号