Through user information, business forms, call access layer interface object, create reflect a class object, in short, is want to by reflecting objects created by connecting the SQLite,
Now, I don't know is my App Config written configuration has a problem, or logical problems, also want to who can instruct me
Predecessor, please see figure: (through checking the tracking)
Here are 4 picture (reduction), the Init method [after parameter assignment, initialize the related objects] source:
///& lt; Summary>
After the parameter///, initialization related objects
///& lt;/summary>
///& lt; Param name="bllFullName & gt;" The BLL business class name (subclasses must implement), the subclass constructor was introduced into this. GetType () FullName
///& lt; Param name="dalAssemblyName & gt;" Data access layer Assembly listing file filename, not including its extension, is set to NULL or default to the Assembly. GetExecutingAssembly (). The GetName (). Name
///& lt; Param name="bllPrefix & gt;" The BLL namespace prefix (BLL) & lt;/param>
///& lt; Param name="dbConfigName & gt;" Database configuration item name & lt;/param>
Protected void Init (string bllFullName, string dalAssemblyName=null string bllPrefix="BLL.")
{
If (string. IsNullOrEmpty (bllFullName))
Throw new ArgumentNullException (" subclass is not set bllFullName business class name!" );
If (string. IsNullOrEmpty (dalAssemblyName))
{
DalAssemblyName=Assembly. GetExecutingAssembly (). The GetName (). The Name;
}
//assignment, ready to build objects
Enclosing bllFullName=bllFullName;
Enclosing dalAssemblyName=dalAssemblyName;
Enclosing bllPrefix=bllPrefix;
# region according to the different kinds of database, constructing the corresponding DAL layer
AppConfig config=new AppConfig ();
String dbType=config. AppConfigGet (" ComponentDbType ");
If (string. IsNullOrEmpty (dbType))
{
DbType="used";
}
DbType=dbType. ToLower ();
String DALPrefix="";
If (dbType=="used")
{
DALPrefix="DALSQL.";
}
Else if (dbType=="access")
{
DALPrefix="DALAccess.";
}
Else if (dbType=="oracle")
{
DALPrefix="DALOracle.";
}
Else if (dbType=="sqlite")
{
DALPrefix="DALSQLite.";
}
Else if (dbType=="mysql")
{
DALPrefix="DALMySql.";
}
# endregion
DalName=bllFullName. Replace (bllPrefix DALPrefix);//replace intermediate BLL. For DAL., DAL classes full name
BaseDal=ReflectThe Create (dalName dalAssemblyName);//constructs corresponding DAL layer data access object class
}
I'm putting the Init method such as a single class, Reflect the reflection action helper classes are also separate packaging,
Also please feel free to comment
CodePudding user response:
Don't want to see the verbosity codeTell how to determine the problem only
Create a unit test or just a console
1. Direct reference to the library
2. New directly that class
(3) in the Assembly load, with reflection direct call
Here all finished do, to talk about your own code
CodePudding user response: