Teach you how to write an ORM (5)

Source: Internet
Author: User
CMMS is the devil

Let's continue with the above content. here we need to implement a plug-in structure to dynamically load data components from the outside. I don't need to talk about the advantages. Someone may ask, plug-ins are good for AOP. Why don't you need them? Just two lines.CodeAre you sure you want to introduce a bunch of things?

Plug-ins must first define interfaces. Of course, we can do anything through refrection, but there is a defined interface that is not half past one for performance improvement.
We introduce a new project to define interfaces. The reason is to eliminate circular references.
Interface Definition: 1 Namespace Alexander. xbase. Interface
2 {
3 Public   Interface Iqueriable
4 {
5 Void Init ( String Connstr, String Configbase );
6 Void Opentranscation ();
7 Void Commit ();
8 Void Rollback ();
9 Object Query4object ( String Action, Object Target );
10 Void Query4list ( String Action, Ref Ilist target, Object Queryparam );
11 Int Query4page ( String Action, Ref Ilist target, Object Queryparam, Int Pageid, Int Pagesize, String Sort, String Direct );
12 Int Query4update ( String Action, Object Target );
13 Object Query4count ( String Action, Object Target );
14 Void Close ();
15 }
16 }

Here you can also define them according to your own ideas, such as the need for more fine-grained operation methods. Anyway, I think these methods are sufficient and even transactions are available, fu he begged ......

The last thing is simple.
We add a factory class in the main project to get the plug-in instance: 1 Namespace Alexander. xbase
2 {
3 Public   Class Queryloader
4 {
5 Public   Static Iqueriable loadquerysession ( String Sessionname)
6 {
7 Sessions session =   New Sessions ();
8 Sessionparameter sp = Session. getsessionbyname (sessionname );
9 String Path = Sp. assambly +   " . Dll " ;
10 Assembly ass = Assembly. loadfrom (PATH );
11 Iqueriable Query = (Iqueriable) ass. createinstance (sp. provider ); // (Sp. provider );
12 Query. INIT (sp. connectionstring, sp. configbase );
13 Return Query;
14 }
15 }
16 }

Is it that simple? This is how simple things are. The key is the two lines.
Assembly ass = assembly. loadfrom (PATH );
Iqueriable query = (iqueriable) ass. createinstance (sp. provider );

Now you can modify the database configuration file mentioned in the previous article to replace the database operation component.

Next we will look at how to map classes.

To be continue .....

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.