How to configure xml file for Spring.Net property injection

372 Views Asked by At

I need to use spring.net to inject dependencies for the implementation of interfaces, using property injection. I am not really familiar with it, can someone kindly explain it to me?

So in the config xml file, the object is the class that is injecting the required dependencies. So the id is the name of that class, but why not use name="PetStore" instead? Also, the type is the full path of that class, so what is the additional parameter "PetStore" after it?

Regarding the properties, what does the name and ref refers to? Does the name refer to the property declared in the class "PetStore" and ref refers to implementation of the interface?

<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; }
}
1

There are 1 best solutions below

0
On
<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 -->

See the chapter 37.2.3 "setter injection" in the quickstart.


In type="PetStore.Services.PetStoreService, PetStore", PetStore.Services.PetStoreService is the full type of the class, including the namespace. PetStore is the name of the assembly.