Ejemplo n.º 1
0
        /// <summary>
        /// Initialize all required interface
        /// </summary>
        /// <param name="container"></param>
        private static void RegisterAllDependencies(Container container)
        {
            container.Register(() => new EzCMSEntities(), Lifestyle.Scoped);
            container.Register <DbContext>(() => new EzCMSEntities(), Lifestyle.Scoped);

            container.Register(typeof(IRepository <>), typeof(Repository <>), Lifestyle.Scoped);
            container.Register(typeof(IHierarchyRepository <>), typeof(HierarchyRepository <>), Lifestyle.Scoped);

            IoCRegister.RegisterDepencies(container);

            // Logger using site settings
            container.Register(typeof(ILogger), () => new Logger(MethodBase.GetCurrentMethod().DeclaringType), Lifestyle.Scoped);

            #region Register controllers

            //container.RegisterMvcControllers(EzCMSUtilities.GetEzCMSAssemblies().ToArray());

            var registeredControllerTypes = SimpleInjectorMvcExtensions.GetControllerTypesToRegister(
                container, EzCMSUtilities.GetEzCMSAssemblies().ToArray());

            // Remove setup controller out of Register process
            registeredControllerTypes = registeredControllerTypes.Where(type => type.Name != "SetupController").ToArray();

            foreach (var controllerType in registeredControllerTypes)
            {
                RegisterController(container, controllerType);
            }

            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Register all IOC
        /// </summary>
        public static void RegisterIOC()
        {
            //Load project assemblies
            LoadProjectAssemblies();

            //Register IOC
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
            container.Register(() => new EzCMSEntities(), Lifestyle.Singleton);
            container.Register <DbContext>(() => new EzCMSEntities(), Lifestyle.Singleton);

            container.Register(typeof(IRepository <>), typeof(Repository <>), Lifestyle.Singleton);
            container.Register(typeof(IHierarchyRepository <>), typeof(HierarchyRepository <>), Lifestyle.Singleton);
            IoCRegister.RegisterDepencies(container);

            // Logger using site settings
            container.Register(typeof(ILogger), () => new Logger(MethodBase.GetCurrentMethod().DeclaringType), Lifestyle.Scoped);
            HostContainer.SetContainer(container);
            container.Verify();
        }