静的コンストラクターを使用して、基本情報でヘルパー クラスを初期化しています。Application_Start
静的コンストラクターは、インスタンスを初期化することによってトリガーされます。
これらのコンストラクターの 1 つで、Entity フレームワークを使用してデータベースからオブジェクトを取得する呼び出しを発行するため、私の懸念が生じました。しかし、返されたオブジェクトは常に でしnull
た。これは、ライフサイクルの早い段階で (EF が完全に終了する前などに) 起動したためだと確信しています。
私の質問は、このソリューション アーキテクチャは安全ですか? (以下は によって呼び出されますApplication_Start
)
public static void OnAppInit()
{
AppSettings AS = new AppSettings(); //Trigger static constructor
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
GeneralConfig.OnAppStart();
ElmahConfig EC = new ElmahConfig(); //Trigger static constructor
BundleConfig.RegisterBundles(BundleTable.Bundles);
AutoMapperConfig.Configure();
ViewResourceHelper VRH = new ViewResourceHelper(); //Trigger static constructor
ExceptionHelper EH = new ExceptionHelper(); //Trigger static constructor
TestEnvironmentHelper.Init();
}