0

我需要使用 spring.net 为接口的实现注入依赖项,使用属性注入。我不是很熟悉它,有人可以向我解释一下吗?

因此,在 config xml 文件中,对象是注入所需依赖项的类。所以 id 是该类的名称,但为什么不使用 name="PetStore" 代替呢?另外,类型是该类的完整路径,那么它后面的附加参数“PetStore”是什么?

关于属性, name 和 ref 指的是什么?名称是指在类“PetStore”中声明的属性,而 ref 是指接口的实现吗?

<object id="PetStore" type="PetStore.Services.PetStoreService, PetStore">
    <property name="AccountDao" ref="AccountDao"/>
    <property name="ItemDao" ref="ItemDao"/>
</object>
public class PetStore : IPetStore
{ 
   public IAccountDao AccountDao { get; set; }
   public IItemDao ItemDao{ get; set; }
}
4

1 回答 1

0
<property name="AccountDao"  <!-- The name of the property you want to inject into -->
          ref="AccountDao"/> <!-- The name of the object definition you want to inject -->

请参阅快速入门中的第 37.2.3 章“setter 注入” 。


type="PetStore.Services.PetStoreService, PetStore",PetStore.Services.PetStoreService是类的完整类型,包括命名空间。PetStore是程序集的名称。

于 2020-10-04T13:46:57.433 回答