Study Notes 41_spring.net

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.