Projects that have participated in development are generally developed in the MVC mode. The following figure shows the framework:
The web interface layer calls the BLL business layer. BLL dynamically generates database operation layer instances that inherit IDAL through the abstract factory DALFactory to perform database operations.
The DALFactory layer dynamically generates IDAL instances through reflection based on web configurations to facilitate BLL layer calls.
In the past, every time an interface (such as IUser) is added to IDAL, DALFactory needs to add a method to generate an instance class that inherits the interface. Rough code:
Public class DataAccess
{
Protected static readonly string path = ConfigurationManager. receivettings ["ReportDemo_DAL"];
Public static IExcel_ReportCell CreateExcel_ReportCell ()
{
String className = path + "." + typeof (IExcel_ReportCell). Name. Substring (1 );
Return (IExcel_ReportCell) Assembly. Load (path). CreateInstance (className );
}
Public static IExcel_Reportcondition CreateExcel_Reportcondition ()
{
String className = path + "." + typeof (IExcel_Reportcondition). Name. Substring (1 );
Return (IExcel_Reportcondition) Assembly. Load (path). CreateInstance (className );
}
// More ....
}
In this way, there will be A problem A: Every time you add an interface, you have to create A factory method. It was too troublesome, So I modified the factory. The Code is as follows:
1 using System. Reflection;
2 using System. Web;
3 using System. Web. Caching;
4 using System. Configuration;
5
6 namespace EHRExcelReprot. DALFactory
7 {
8 public sealed class ObjDataAccess <T>
9 {
10 // obtain the configuration information of the web. confg File
11 private static readonly string path = ConfigurationManager. deleettings ["ExcelReportDAL"];
12 public static T Get ()
13 {
14 // Note: Make sure that the name of the interface class is only one 'I' letter before the class name that inherits it.
15 // For example, Interface Class Name: IUser, which inherits the class: User
16 string CacheKey = path +