最佳答案
我最近创建了一个接口层,以区分 DataAccessProvider 和我们的业务逻辑层。 通过这种方法,我们可以通过更改 Web/App 中的值,随时更改 DataAccessProvider 的选择。配置。 (如有需要,可提供更多详情)。
无论如何,要做到这一点,我们使用反射来完成我们可以工作的 DataProvider 类。
/// <summary>
/// The constructor will create a new provider with the use of reflection.
/// If the assembly could not be loaded an AssemblyNotFoundException will be thrown.
/// </summary>
public DataAccessProviderFactory()
{
string providerName = ConfigurationManager.AppSettings["DataProvider"];
string providerFactoryName = ConfigurationManager.AppSettings["DataProviderFactory"];
try
{
activeProvider = Assembly.Load(providerName);
activeDataProviderFactory = (IDataProviderFactory)activeProvider.CreateInstance(providerFactoryName);
}
catch
{
throw new AssemblyNotFoundException();
}
}
但现在我想知道反应有多慢?