C# 什么是 Unity InjectionConstructor 属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/458483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is Unity InjectionConstructor Attribute?
提问by Yoann. B
What is Unity InjectionConstructor Attribute and how it works ?
什么是 Unity InjectionConstructor 属性及其工作原理?
回答by Ryan Lanciaux
Basically this tells Unity to use the constructor that is specified with the attribute. Please read this postfor more information.
基本上这告诉 Unity 使用由属性指定的构造函数。请阅读这篇文章以获取更多信息。
回答by Bogdan
This attribute is used to indicate which constructor to choose when the container attempts to build a type.
此属性用于指示当容器尝试构建类型时选择哪个构造函数。
myclass {
[InjectionConstructor]
public myclass(interface1:XYZ, .....){}
}
It does something similar to the InjectionConstructor (not the attribute) in a more declarative way. But it lacks some features like using a named interface ex:
它以更具声明性的方式执行类似于 InjectionConstructor(而不是属性)的操作。但它缺少一些功能,例如使用命名接口 ex:
new InjectionConstructor(new ResolvedParameter<IMyInterface>("implementation # 1"));