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 .....