![](/img/trans.png)
[英]Unity - DependencyAttribute or Interface Inheritance for constructor injection
[英]What name will DependencyAttribute instance have if default constructor is used?
我有一个代码:
[Dependency] public string MyProperty { get; set; }
而DependencyAttribute
类具有属性Name
。
在这种情况下它将包含什么值?
它是null
还是nameof(MyProperty)
?
不幸的是,我还没有看到DependencyAttribute
类的源代码。 也许有人可以提供链接。
提前致谢!
该值将为空。 在没有显式名称的情况下,null是Unity使用的默认名称(例如,在对RegisterType()
调用中)。 具体而言,在DependencyAttribute
方面:
public DependencyAttribute()
: this(null) { }
/// <summary>
/// Create an instance of <see cref="DependencyAttribute"/> with the given name.
/// </summary>
/// <param name="name">Name to use when resolving this dependency.</param>
public DependencyAttribute(string name)
{
this.name = name;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.