Example #1
0
        /// <summary>
        /// Creates the configured BetterCMS root dependencies container.
        /// </summary>
        /// <returns>The container builder.</returns>
        public static ContainerBuilder InitializeContainer(ContainerBuilder builder = null)
        {
            if (builder == null)
            {
                builder = new ContainerBuilder();
            }

            if (isStarted)
            {
                return(builder);
            }

            builder = WebApplicationContext.InitializeContainer(builder, Config);
            builder.RegisterType <DefaultTextEncryptor>().As <ITextEncryptor>().SingleInstance();

            builder.RegisterType <CmsModulesRegistration>()
            .As <IModulesRegistration>()
            .As <IWebModulesRegistration>()
            .As <ICmsModulesRegistration>()
            .SingleInstance();

            builder.RegisterInstance(Config)
            .As <ICmsConfiguration>()
            .As <IWebConfiguration>()
            .As <IConfiguration>()
            .SingleInstance();

            builder.RegisterType <DefaultCmsHost>()
            .As <IWebApplicationHost>()
            .As <ICmsHost>()
            .SingleInstance();

            RegisterCacheService(builder);
            RegisterStorageService(builder);

            isStarted = true;

            return(builder);
        }
Example #2
0
        /// <summary>
        /// Method to run logic before application start (as PreApplicationStartMethod). Do not run this method from your code.
        /// </summary>
        public static void PreApplicationStart()
        {
            if (isStarted)
            {
                return;
            }

            ILog logger;

            try
            {
                logger = LogManager.GetCurrentClassLogger();
                logger.Info("Starting Web Application...");
            }
            catch (Exception ex)
            {
                throw new CoreException("Logging is not working. A reason may be that Common.Logging section is not configured in web.config.", ex);
            }

            try
            {
                logger.Info("Creating Web Application context dependencies container...");
                ContextScopeProvider.RegisterTypes(WebApplicationContext.InitializeContainer());
            }
            catch (Exception ex)
            {
                string message = "Failed to create Web Application context dependencies container.";
                logger.Fatal(message, ex);

                throw new CoreException(message, ex);
            }

            PreStartWebApplication();

            isStarted = true;
        }