Ejemplo n.º 1
0
 public UserAnswerService(IRepository <UserAnswer> userAnswerRepository
                          , IRepository <UserAnswerDetail> userAnswerDetailRepository
                          , IRepository <UserAnswerDetail_Media> userAnswerDetailMediaRepository
                          , IRepository <UserAnswerQueue> userAnswerQueueRepository
                          , IPropertyService propertyService
                          , ICacheManager cacheManager
                          , IEventPublisher eventPublisher
                          , IQuestionBankService questionBankService
                          , IUserAttributeService userAttributeService
                          , IWorkContext workContext
                          , IUserService userService
                          , ILogger logger
                          , IWordsSubstitutionService wordsSubstitutionService
                          , WeiConfig weiConfig)
 {
     this._userAnswerRepository            = userAnswerRepository;
     this._userAnswerDetailRepository      = userAnswerDetailRepository;
     this._userAnswerDetailMediaRepository = userAnswerDetailMediaRepository;
     this._userAnswerQueueRepository       = userAnswerQueueRepository;
     this._propertyService      = propertyService;
     this._cacheManager         = cacheManager;
     this._eventPublisher       = eventPublisher;
     this._questionBankService  = questionBankService;
     this._userAttributeService = userAttributeService;
     this._userService          = userService;
     this._workContext          = workContext;
     this._logger = logger;
     this._wordsSubstitutionService = wordsSubstitutionService;
     this._weiConfig = weiConfig;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize components and plugins in the nop environment.
        /// </summary>
        /// <param name="config">Config</param>
        public void Initialize(WeiConfig config)
        {
            //register dependencies
            RegisterDependencies(config);

            //startup tasks  WeiChen
            //if (!config.IgnoreStartupTasks)
            //{
            //    RunStartupTasks();
            //}
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Register dependencies
        /// </summary>
        /// <param name="config">Config</param>
        protected virtual void RegisterDependencies(WeiConfig config)
        {
            var builder   = new ContainerBuilder();
            var container = builder.Build();

            this._containerManager = new ContainerManager(container);

            //we create new instance of ContainerBuilder
            //because Build() or Update() method can only be called once on a ContainerBuilder.

            //dependencies
            var typeFinder = new WebAppTypeFinder();

            builder = new ContainerBuilder();
            builder.RegisterInstance(config).As <WeiConfig>().SingleInstance();
            builder.RegisterInstance(this).As <IEngine>().SingleInstance();
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();
            builder.Update(container);

            //register dependencies provided by other assemblies
            builder = new ContainerBuilder();
            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);
            }
            builder.Update(container);

            //set dependency resolver
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, WeiConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
            .As <HttpContextBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerLifetimeScope();
            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();
            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());
            builder.RegisterApiControllers(typeFinder.GetAssemblies().ToArray());

            //data layer
            var dataSettingsManager  = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DataSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DataSettings>())).As <BaseDataProviderManager>().InstancePerDependency();


            builder.Register(x => x.Resolve <BaseDataProviderManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <IDbContext>(c => new WeiObjectContext("DefaultConnection")).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <IDbContext>(c => new WeiObjectContext("DefaultConnection")).InstancePerLifetimeScope();
            }


            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("wei_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("wei_cache_per_request").InstancePerLifetimeScope();

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();
            builder.RegisterType <DBHelp>().As <DBHelp>().InstancePerLifetimeScope();


            builder.RegisterType <CommonService>().As <ICommonService>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            builder.RegisterType <PropertyService>().As <IPropertyService>().InstancePerLifetimeScope();
            builder.RegisterType <WordsSubstitutionService>().As <IWordsSubstitutionService>().InstancePerLifetimeScope();
            builder.RegisterType <DBService>().As <IDBService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <UserAttributeService>().As <IUserAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();

            builder.RegisterType <UserAnswerService>().As <IUserAnswerService>().InstancePerLifetimeScope();
            builder.RegisterType <QuestionBankService>().As <IQuestionBankService>().InstancePerLifetimeScope();

            //Register event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
        }