Spring.net: The container is responsible for creating the object, the container reads the configuration file to initialize the object, the configuration file must conform to the spring.net paradigm;
Preparation Material: Common.loggin.dll,spring.core.dll
The first step: Configure App. Config, you can usually go to the Internet to find a standard spring.net configuration file to see
<Spring>
<context>
<resource uri= "Config://spring/objects" >//describes where all the objects of the container are configured
<resource uri= "File://Dals.xml" >//this profile, also placed in the unified directory of App. Config, and the file is also very special
Note: For a configuration file build operation, if the file is to be generated as an embedded resource or always generated
<resource uri= "Assembly://myassembly/projectname (generally also assembly name)/xxxx.xml" >//in an assembly XML way
</context>
<objects xmlns= "http://..." >
<description>....</...>
<object name= "is typically type name" type = "namespace.xxxx. Class name (full name of the class), namespace (where the assembly name is)" ></. >
</objects>
</<Spring>
Step Two: Create an instance with a container
Iapplicationcontext CTX = Contextregistry.getcontext ();//is actually the assembly read configuration file, create context
var dal = ctx. GetObject ("type name") as NAMESPACE.XXXX.I class name;//In fact, as an interface type, the inside is actually the assembly read the configuration file, in the back reflection creates an instance.
It is the configuration file that determines what is created to implement an instance of an interface
So the configuration file, to write a regular, as far as possible to find/replace can be replaced by a key
Other configuration file notation
<objects xmlns= "http://" xmlns:xsi= "http://www.w3.org/...." xis:schemalocation = "http://" >
<object id= "..." type= "..." ></object>
<object id= "..." type= "..." ></object>
</objects>
Spring.net Injection Method:
Attribute injection:
<objects>
<object name= "Xxtype1" type= "Xxx.xxx.xxxtype" >
<object name= "Xxtype" type= "Xxx.xxx.xxxtype" >
<property name= "name" value= "xxxxx" >//the configuration of simple properties
<property name= "Complex attribute" ref= "Xxtype1"/>//complex properties, associated with Xxxtype1 above
</object>
<objects>
Constructor injection:
<object name= "..." type= "..." >
<constructor-arg index= "0" value= "xxx" >//the first parameter of the constructor is injected, in general, as little as possible
</object>
Study Notes 41_spring.net