示例#1
0
 public IAmbethPlatformContext CreatePlatformContext()
 {
     return(AmbethPlatformContext.Create(properties, providerModuleTypes.ToArray(),
                                         frameworkModuleTypes.ToArray(),
                                         bootstrapModuleTypes.ToArray(),
                                         providerModules.ToArray(),
                                         frameworkModules.ToArray(),
                                         bootstrapModules.ToArray()));
 }
示例#2
0
        public static IAmbethPlatformContext Create(Properties props, Type[] providerModules, Type[] frameworkModules, Type[] bootstrapModules,
                                                    IInitializingModule[] providerModuleInstances, IInitializingModule[] frameworkModuleInstances,
                                                    IInitializingModule[] bootstrapModuleInstances)
        {
            ParamChecker.AssertParamNotNull(props, "props");

            IServiceContext       bootstrapContext = null;
            AmbethPlatformContext apc = new AmbethPlatformContext();

            try
            {
                IInitializingModule[] providerModuleInstancesCopy = new IInitializingModule[providerModuleInstances.Length + 1];
                Array.Copy(providerModuleInstances, 0, providerModuleInstancesCopy, 0, providerModuleInstances.Length);
                providerModuleInstancesCopy[providerModuleInstancesCopy.Length - 1] = new AmbethPlatformContextModule(apc);
                providerModuleInstances = providerModuleInstancesCopy;

                bootstrapContext = BeanContextFactory.CreateBootstrap(props, providerModules, providerModuleInstances);

                IList <IModuleProvider> moduleProviders = bootstrapContext.GetImplementingObjects <IModuleProvider>();
                for (int a = moduleProviders.Count; a-- > 0;)
                {
                    IModuleProvider moduleProvider     = moduleProviders[a];
                    Type[]          mpFrameworkModules = moduleProvider.GetFrameworkModules();
                    Type[]          mpBootstrapModules = moduleProvider.GetBootstrapModules();
                    frameworkModules = ModuleUtil.MergeModules(mpFrameworkModules, frameworkModules);
                    bootstrapModules = ModuleUtil.MergeModules(mpBootstrapModules, bootstrapModules);
                }
                IServiceContext frameworkBeanContext = bootstrapContext;

                if (frameworkModules.Length > 0 || frameworkModuleInstances.Length > 0)
                {
                    frameworkBeanContext = bootstrapContext.CreateService("framework", delegate(IBeanContextFactory childContextFactory)
                    {
                        for (int a = frameworkModuleInstances.Length; a-- > 0;)
                        {
                            childContextFactory.RegisterExternalBean(frameworkModuleInstances[a]);
                        }
                    }, frameworkModules);
                }

                ILightweightTransaction transaction = frameworkBeanContext.GetService <ILightweightTransaction>(false);
                if (transaction != null)
                {
                    ILogger log = LoggerFactory.GetLogger(typeof(AmbethPlatformContext), props);
                    if (log.InfoEnabled)
                    {
                        log.Info("Starting initial database transaction to receive metadata for OR-Mappings...");
                    }
                    transaction.RunInTransaction(delegate()
                    {
                        // Intended blank
                    });
                    if (log.InfoEnabled)
                    {
                        log.Info("Initial database transaction processed successfully");
                    }
                }
                IServiceContext applicationBeanContext = frameworkBeanContext;

                if (bootstrapModules.Length > 0 || bootstrapModuleInstances.Length > 0)
                {
                    applicationBeanContext = frameworkBeanContext.CreateService("application", delegate(IBeanContextFactory childContextFactory)
                    {
                        for (int a = bootstrapModuleInstances.Length; a-- > 0;)
                        {
                            childContextFactory.RegisterExternalBean(bootstrapModuleInstances[a]);
                        }
                    }, bootstrapModules);
                }
                apc.beanContext = applicationBeanContext;
                return(apc);
            }
            catch (Exception)
            {
                if (bootstrapContext != null)
                {
                    IThreadLocalCleanupController tlCleanupController = bootstrapContext.GetService <IThreadLocalCleanupController>();
                    bootstrapContext.Dispose();
                    tlCleanupController.CleanupThreadLocal();
                }
                throw;
            }
        }
示例#3
0
 public AmbethPlatformContextModule(AmbethPlatformContext apc)
 {
     this.apc = apc;
 }