私のAsp.net MVCプロジェクトでは
Unityコンテナを初期化するブートラッパーがあります。
理由はわかりませんが、わかります
System.Core.dll で「System.StackOverflowException」タイプの未処理の例外が発生しました
再確認しましたが、登録は初期化子でのみ行われます。
すべての依存関係は、ctor にのみ注入されます。
何が原因でしょうか?
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
Initializer.Initialize();
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
後に失敗しますBundleConfig.RegisterBundles(BundleTable.Bundles);
public static class Initializer
{
private static bool isInitialize;
private static readonly object LockObj = new object();
private static IUnityContainer defaultContainer = new UnityContainer();
static Initializer()
{
Initialize();
}
public static void Initialize()
{
if (isInitialize)
return;
lock (LockObj)
{
IUnityContainer container = defaultContainer;
//registering Unity for MVC
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
//registering Unity for web API
// GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
#region managers
container.RegisterType<ISettingsManager, SettingsManager>();
container.RegisterType<IMamDataManager, MamDataManager>();
container.RegisterType<IAppsDataManager, AppsDataManager>();
#endregion
#region Dals
container.RegisterType<IDal<ClientService.DAL.EntityFramework.App>, AppsDal>();
#endregion Dals
#region cache
container.RegisterType<ICache<string, ClientService.DAL.EntityFramework.Group>, GroupsCache>(new ContainerControlledLifetimeManager());
container.RegisterType<ICache<string, ClientService.DAL.EntityFramework.App>, AppsCache>(new ContainerControlledLifetimeManager());
container.RegisterType<ICache<string, SettingsServiceData>, SettingsServiceDataCache>(new ContainerControlledLifetimeManager());
#endregion cache
#region Pollers
container.RegisterType<IPoller<ClientService.DAL.EntityFramework.Group>, GroupsPoller>(new ContainerControlledLifetimeManager());
container.RegisterType<IPoller<ClientService.DAL.EntityFramework.App>, AppsPoller>(new ContainerControlledLifetimeManager());
container.RegisterType<IPoller<SettingsServiceData>, SettingsPoller>(new ContainerControlledLifetimeManager());
#endregion Pollers
container.RegisterType<IDefaultConfigurationGroupSingleton, DefaultConfigurationGroupSingleton>(new ContainerControlledLifetimeManager());
container.RegisterType<IApplicationLogger, Log4NetLogger>();
if (!isInitialize)
{
isInitialize = true;
}
}
}
}