Ejemplo n.º 1
0
        /// <summary>
        /// Register dependencies
        /// </summary>
        /// <param name="config">Config</param>
        protected virtual void RegisterDependencies(DreamSaleConfig config)
        {
            var builder = new ContainerBuilder();

            //dependencies
            var typeFinder = new WebAppTypeFinder();

            builder.RegisterInstance(config).As <DreamSaleConfig>().SingleInstance();
            builder.RegisterInstance(this).As <IEngine>().SingleInstance();
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();

            //register dependencies provided by other assemblies
            var drTypes     = typeFinder.FindClassesOfType <IDependencyRegistrar>();
            var drInstances = new List <IDependencyRegistrar>();

            foreach (var drType in drTypes)
            {
                drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType));
            }
            //sort
            drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
            foreach (var dependencyRegistrar in drInstances)
            {
                dependencyRegistrar.Register(builder, typeFinder, config);
            }

            //web helper
            //builder.RegisterType<WebHelper>().As<IWebHelper>().InstancePerLifetimeScope();



            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager = new DataSettingsManager();

            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();

            var container = builder.Build();

            this._containerManager = new ContainerManager(container);

            // Set the dependency resolver for MVC.
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            //HttpConfiguration config = new HttpConfiguration();

            // Set the dependency resolver for Web API.
            //var webApiResolver = new AutofacWebApiDependencyResolver(container);
            //config.DependencyResolver = webApiResolver;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Register mapping
        /// </summary>
        /// <param name="config">Config</param>
        //protected virtual void RegisterMapperConfiguration(DreamSaleConfig config)
        //{
        //    //dependencies
        //    var typeFinder = new WebAppTypeFinder();

        //    //register mapper configurations provided by other assemblies
        //    var mcTypes = typeFinder.FindClassesOfType<IMapperConfiguration>();
        //    var mcInstances = new List<IMapperConfiguration>();
        //    foreach (var mcType in mcTypes)
        //        mcInstances.Add((IMapperConfiguration)Activator.CreateInstance(mcType));
        //    //sort
        //    mcInstances = mcInstances.AsQueryable().OrderBy(t => t.Order).ToList();
        //    //get configurations
        //    var configurationActions = new List<Action<IMapperConfigurationExpression>>();
        //    foreach (var mc in mcInstances)
        //        configurationActions.Add(mc.GetConfiguration());
        //    //register
        //    AutoMapperConfiguration.Init(configurationActions);
        //}

        #endregion

        #region Methods

        /// <summary>
        /// Initialize components and plugins in the DreamSale environment.
        /// </summary>
        /// <param name="config">Config</param>
        public void Initialize(DreamSaleConfig config)
        {
            //register dependencies
            RegisterDependencies(config);

            //register mapper configurations
            //RegisterMapperConfiguration(config);

            //startup tasks
            if (!config.IgnoreStartupTasks)
            {
                RunStartupTasks();
            }
        }