私は最近、DataAccessProviderとビジネスロジックレイヤーを区別するためのインターフェースレイヤーを作成しました。 このアプローチでは、Web/App.Configの値を変更して、いつでも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();
}
}
しかし、今私はどのように遅い反射があるのだろうか?
これをベンチマークするテストハーネスを作成するのは簡単でしょうか? – marijne
工場がシングルトンの場合、Assembly.Loadは一度だけ呼び出されますか? – CVertex
http://stackoverflow.com/questions/25458/how-costly-is-net-reflection?rq=1 – nawfal