Beispiel #1
0
        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            // TODO: Register your types here
            // container.RegisterType<IProductRepository, ProductRepository>();

            //string connectionString = WebConfigurationManager.ConnectionStrings["cs"].ConnectionString;

            string   hibernateCfgFileName = System.Web.Hosting.HostingEnvironment.MapPath("~/bin/hibernate.cfg.xml");
            XElement root  = XElement.Load(hibernateCfgFileName);
            var      nsMgr = new XmlNamespaceManager(new NameTable());

            nsMgr.AddNamespace("NC", "urn:nhibernate-configuration-2.2");
            string connectionString = root.XPathSelectElement("//NC:property[@name='connection.connection_string']", nsMgr).Value;

            //регистрация NHibernate-репозиториев
            NHibernateDataInstaller.Install(container, new PerRequestLifetimeManager());
            NHibernateRepositoryInstaller.Install(container);

            //регистрация кэша
            string redisConnectionString = WebConfigurationManager.AppSettings["cache:RedisConnectionString"];

            CacheLocation defaultLocation = CacheLocation.InMemory;

            Enum.TryParse(WebConfigurationManager.AppSettings["cache:DefaultLocation"], out defaultLocation);


            CacheInstaller.Install(redisConnectionString, defaultLocation, container, new PerRequestLifetimeManager());

            //регистрация Мигратора
            MigratorInstaller.Install(container, connectionString);

            DataServiceCommonInstaller.Install(container);
            //регистрация дата-сервисов
            DataServiceInstaller.Install(container);

            //регистрация шины
            EventBusInstaller.Install(container,
                                      WebConfigurationManager.AppSettings["RabbitMQHost"],
                                      WebConfigurationManager.AppSettings["ServiceAddress"],
                                      WebConfigurationManager.AppSettings["RabbitMQUserName"],
                                      WebConfigurationManager.AppSettings["RabbitMQPassword"]);

            container.RegisterType <JsResourceHelper>();
        }
Beispiel #2
0
        private static void RegisterTypes(IUnityContainer container)
        {
            NHibernateDataInstaller.Install(container, new ContainerControlledLifetimeManager());
            NHibernateRepositoryInstaller.Install(container);
            DataServiceCommonInstaller.Install(container);

            //логеры
            container.RegisterType <ILog>("EmailSender", new InjectionFactory(c => Logger.Get <EmailSender>()));
            container.RegisterType <ILog>("WebPushSender", new InjectionFactory(c => Logger.Get <WebPushSender>()));

            container.RegisterType <ILog>("RequestAppEventHandler", new InjectionFactory(c => Logger.Get <RequestAppEventHandler>()));
            container.RegisterType <ILog>("RequestDeedlineAppEventHandler", new InjectionFactory(c => Logger.Get <RequestDeedlineAppEventHandler>()));
            container.RegisterType <ILog>("UserPasswordRecoveryAppEventHandler", new InjectionFactory(c => Logger.Get <UserPasswordRecoveryAppEventHandler>()));
            container.RegisterType <ILog>("UserRegisterAppEventHandler", new InjectionFactory(c => Logger.Get <UserRegisterAppEventHandler>()));

            container.RegisterType <ILog>("RequestAppEventConsumer", new InjectionFactory(c => Logger.Get <RequestAppEventConsumer>()));
            container.RegisterType <ILog>("RequestDeedlineAppEventConsumer", new InjectionFactory(c => Logger.Get <RequestDeedlineAppEventConsumer>()));
            container.RegisterType <ILog>("UserPasswordRecoveryAppEventConsumer", new InjectionFactory(c => Logger.Get <UserPasswordRecoveryAppEventConsumer>()));
            container.RegisterType <ILog>("UserRegisterAppEventConsumer", new InjectionFactory(c => Logger.Get <UserRegisterAppEventConsumer>()));


            //шаблонизатор
            container.RegisterType <IEmailTemplateService, RazorEmailTemplateService>();

            //отправщики сообщений
            container.RegisterType <ISender, EmailSender>("EmailSender",
                                                          new InjectionConstructor(
                                                              container.Resolve <IEmailTemplateService>(),
                                                              container.Resolve <ILog>("EmailSender")
                                                              ));

            string oneSignalAppId = ConfigurationManager.AppSettings["OneSignal:AppId"];

            if (!String.IsNullOrWhiteSpace(oneSignalAppId))
            {
                container.RegisterType <ISender, WebPushSender>("WebPushSender",
                                                                new InjectionConstructor(
                                                                    oneSignalAppId,
                                                                    container.Resolve <ILog>("WebPushSender")
                                                                    ));
            }

            IList <ISender> senders = new List <ISender>();

            senders.Add(container.Resolve <ISender>("EmailSender"));
            if (!String.IsNullOrWhiteSpace(oneSignalAppId))
            {
                senders.Add(container.Resolve <ISender>("WebPushSender"));
            }

            DataServiceCommonInstaller.Install(container);


            //обработчикм сообщений из шины
            container.RegisterType <IAppEventHandler <IRequestAppEvent>, RequestAppEventHandler>(
                new InjectionConstructor(
                    container.Resolve <IQueryHandler>(),
                    container.Resolve <IStatusRequestMapService>(),
                    container.Resolve <ILog>("RequestAppEventHandler"),
                    senders
                    ));

            container.RegisterType <IAppEventHandler <IRequestDeedlineAppEvent>, RequestDeedlineAppEventHandler>(
                new InjectionConstructor(
                    container.Resolve <IQueryHandler>(),
                    container.Resolve <ILog>("RequestDeedlineAppEventHandler"),
                    senders
                    ));

            container.RegisterType <IAppEventHandler <IUserPasswordRecoveryAppEvent>, UserPasswordRecoveryAppEventHandler>(
                new InjectionConstructor(
                    container.Resolve <ILog>("UserPasswordRecoveryAppEventHandler"),
                    senders[0]
                    ));

            container.RegisterType <IAppEventHandler <IUserRegisterAppEvent>, UserRegisterAppEventHandler>(
                new InjectionConstructor(
                    container.Resolve <ILog>("UserRegisterAppEventHandler"),
                    senders[0]
                    ));


            //получатели сообщений из шины
            container.RegisterType <IConsumer <IRequestAppEvent>, RequestAppEventConsumer>(
                new InjectionConstructor(
                    container.Resolve <IAppEventHandler <IRequestAppEvent> >(),
                    container.Resolve <ILog>("RequestAppEventConsumer")
                    ));

            container.RegisterType <IConsumer <IRequestDeedlineAppEvent>, RequestDeedlineAppEventConsumer>(
                new InjectionConstructor(
                    container.Resolve <IAppEventHandler <IRequestDeedlineAppEvent> >(),
                    container.Resolve <ILog>("RequestDeedlineAppEventConsumer")
                    ));

            container.RegisterType <IConsumer <IUserPasswordRecoveryAppEvent>, UserPasswordRecoveryAppEventConsumer>(
                new InjectionConstructor(
                    container.Resolve <IAppEventHandler <IUserPasswordRecoveryAppEvent> >(),
                    container.Resolve <ILog>("UserPasswordRecoveryAppEventConsumer")
                    ));

            container.RegisterType <IConsumer <IUserRegisterAppEvent>, UserRegisterAppEventConsumer>(
                new InjectionConstructor(
                    container.Resolve <IAppEventHandler <IUserRegisterAppEvent> >(),
                    container.Resolve <ILog>("UserRegisterAppEventConsumer")
                    ));
        }