Sqlcenter and IOC Modes

Source: Internet
Author: User
When learning sqlcenter, the default proxy mode and IOC mode are used in the generators design mentioned by the boss. I saw it again later in the evening. Haha, I feel a little overwhelmed. Indeed. Write your own experience below.
The default proxy mode is not much said. I mainly look at the embodiment of IOC. Recently I am studying spring. net, so I am particularly sensitive to words like IOC and AOP.
There are too many good IOC in the garden. Article . I briefly described my feelings and contacted sqlcenter.
The emergence of IOC is to decouple. Make the class or component "do not talk to strangers" as much as possible ". But they must have such a connection. What should they do? The IOC container appears. Use such a container to manage the connections between these components. Such containers include spring. net, Castle, and picocontainer, hiemind, and xwork in. net. In IOC, these frameworks become the master Program Is responsible for coordinating events and application activities, as well as lifecycle.
In sqlcenter, generatorservice plays such a role to a certain extent. It obtains the relationship between components through the configuration file and is responsible for creation and scheduling. Of course, the function of such a container has not been fully completed yet, but the idea has fully reflected the IOC model.

See the following Configuration:

Configuration Information
1   < Generators >
2 < Item Target = "Sqlcenter. Entities. Field, sqlcenter. Entities" Type = "Default" Generator = "Sqlcenter. generators. fieldgenerator, sqlcenter. GENERATORS" />
3 < Item Target = "Sqlcenter. Entities. Order, sqlcenter. Entities" Type = "Default" Generator = "Sqlcenter. generators. ordergenerator, sqlcenter. GENERATORS" />
4 < Item Target = "Sqlcenter. Entities. Join, sqlcenter. Entities" Type = "Default" Generator = "Sqlcenter. generators. joingenerator, sqlcenter. GENERATORS" />
5 < Item Target = "Sqlcenter. Entities. fromtable, sqlcenter. Entities" Type = "Default" Generator = "Sqlcenter. generators. fromtablegenerator, sqlcenter. GENERATORS" />
6
7 </ Generators >

Then, the basic functions of the container are implemented through the nativegetcalculator method:

Simple container
1 Private Static object nativegetcalculator (nameobjectcollection cache, calculatorconfigurationcollection ations, type expressiontype, string dbtype)
2 {
3 Dbtype = dbtype. tolower (). Trim ();
4 Hashtable item = cache [dbtype] As hashtable;
5 If (item = NULL)
6 {
7 Lock (cache)
8 {
9 Item = new hashtable ();
10 Cache. Add (dbtype, item );
11 }
12 }
13 Object calculator = item [expressiontype];
14 If (calculator = NULL)
15 {
16 Calculatorconfiguration Config = tolerations. fromtarget (expressiontype, dbtype );
17 If (config! = NULL)
18 {
19 Lock (item)
20 {
21 If (calculator! = NULL)
22 {
23 Calculator = activator. createinstance (config. calculator, bindingflags. nonpublic | bindingflags. Public | bindingflags. instance, null, new object [] {}, null );
24 Item. Add (expressiontype, calculator );
25 }
26 }
27 }
28 Else if (string. Compare (dbtype, "default", true )! = 0)
29 {
30 Config = configurations. fromtarget (expressiontype, "default ");
31 If (config! = NULL)
32 {
33 Lock (item)
34 {
35 If (calculator = NULL)
36 {
37 Calculator = activator. createinstance (config. calculator, bindingflags. nonpublic | bindingflags. Public | bindingflags. instance, null, new object [] {}, null );
38 If (calculator is igenerator)
39 {
40 (Igenerator) calculator). type = dbtype;
41 }
42 Item. Add (expressiontype, calculator );
43 }
44 }
45 }
46 }
47 }
48 Return calculator;
49 }
50

With this implementation, you can achieve "Hot swapping" of components and container management of component relationships.
Today, I finally debugged a simple demo Based on spring. net. Then I looked back at sqlcenter and said to myself: this is the spirit of IOC!
By the way, you need to pay attention to it. Of course, this attention is very small, maybe because I am not familiar with configuring write programs. There is always a problem when debugging your own demo. Finally, under the guidance of the boss, I found that the original error was caused by this Configuration:

<Item target = "sqlcenter. Entities. fromtable, sqlcenter. Entities" type = "default" generator = "sqlcenter. generators. fromtablegenerator, sqlcenter. GENERATORS"/>

How to write the generator here? ====> Namespace. classname, assembly

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.