예제 #1
0
        static void Main(string[] args)
        {
            InjectContainer.RegisterType <IDomainRepository, DomainRepository>();
            InjectContainer.RegisterType <IEventStorage, SQLServerEventStorage>();
            InjectContainer.RegisterInstance <IEventPublisher>(new RabbitMQEventPublisher("amqp://localhost:5672"));
            InjectContainer.RegisterType <IEventDBConnectionStringProvider, AppSettingEventDBConnectionStringProvider>();

            //这一部分需要重构到配置文件中
            InjectContainer.RegisterType <IInventoryReadDBConnectionStringProvider, AppsettingInventoryReadDBConnectionStringProvider>();
            InjectContainer.RegisterType <IInventoryWriteDBConnectionStringProvider, AppsettingInventoryWriteDBConnectionStringProvider>();
            InjectContainer.RegisterType <IInventoryReportDataAccessor, InventoryReportDataAccessor>();

            InjectContainer.RegisterType <IRentalReadDBConnectionStringProvider, AppsettingRentalReadDBConnectionStringProvider>();
            InjectContainer.RegisterType <IRentalWriteDBConnectionStringProvider, AppsettingRentalWriteDBConnectionStringProvider>();
            InjectContainer.RegisterType <IRentalReportDataAccessor, RentalReportDataAccessor>();
            InjectContainer.RegisterType <ICommandTracker, SignalRCommandTracker>();


            var handlers = BuildHandlerConfigurations();

            HandlerRegister register = new HandlerRegister();

            foreach (var handler in handlers)
            {
                Console.WriteLine($"Starting handler '{handler.Name}'");
                RegisterCommandHandlers(handler.LibraryName);
                RegisterEventHandlers(handler.LibraryName);
                register.RegisterAndStart(handler.LibraryName);

                Console.WriteLine($"Started handler '{handler.Name}'");
            }
        }
예제 #2
0
 private void InjectService()
 {
     InjectContainer.RegisterType <IPasswordHasher, PlainTextPasswordHasher>();
     InjectContainer.RegisterType <IIdentityReadDBConnectionStringProvider, AppsettingRepositoryReadDBConnectionStringProvider>();
     InjectContainer.RegisterType <IIdentityWriteDBConnectionStringProvider, AppsettingRepositoryWriteDBConnectionStringProvider>();
     InjectContainer.RegisterType <IIdentityReportDataAccessor, IdentityReportDataAccessor>();
 }
예제 #3
0
        private void InjectService()
        {
            InjectContainer.RegisterType <ILogDBConnectionStringProvider, AppsettingLogDBConnectionStringProvider>();
            InjectContainer.RegisterType <ILogger, Logger>();

            InjectContainer.RegisterType <IConsulAPIUrlProvider, AppsettingConsulAPIUrlProvider>();
            InjectContainer.RegisterType <IServiceDiscovery, ConsulServiceDiscovery>();
        }
예제 #4
0
 private void InjectService()
 {
     InjectContainer.RegisterInstance <ICommandPublisher>(new RabbitMQCommandPublisher("amqp://localhost:5672"));
     InjectContainer.RegisterType <IInventoryReadDBConnectionStringProvider, AppsettingInventoryReadDBConnectionStringProvider>();
     InjectContainer.RegisterType <IInventoryWriteDBConnectionStringProvider, AppsettingInventoryWriteDBConnectionStringProvider>();
     InjectContainer.RegisterType <IInventoryReportDataAccessor, InventoryReportDataAccessor>();
     InjectContainer.RegisterType <ICommandTracker, SignalRCommandTracker>();
 }
예제 #5
0
        public static void Register()
        {
            InjectContainer.RegisterType <ICommonService, CommonService>();

            InjectContainer.RegisterType <ILogHelper, LogHelper>();

            InjectContainer.RegisterType <IFileService, FileService>();
        }
예제 #6
0
파일: Startup.cs 프로젝트: wanglong/Library
 private void InjectService()
 {
     InjectContainer.RegisterType <IRabbitMQUrlProvider, AppsettingRabbitMQUrlProvider>();
     InjectContainer.RegisterType <ICommandPublisher, RabbitMQCommandPublisher>();
     InjectContainer.RegisterType <IInventoryReadDBConnectionStringProvider, AppsettingInventoryReadDBConnectionStringProvider>();
     InjectContainer.RegisterType <IInventoryWriteDBConnectionStringProvider, AppsettingInventoryWriteDBConnectionStringProvider>();
     InjectContainer.RegisterType <IInventoryReportDataAccessor, InventoryReportDataAccessor>();
     InjectContainer.RegisterType <ICommandTracker, SignalRCommandTracker>();
 }
예제 #7
0
 protected virtual void BeforeInject()
 {
     InjectContainer.RegisterType <IConfigurationReader, ConfigurationReader>();
     InjectContainer.RegisterInstance <ILogHelper>(new Log4netHelper());
     #if DEBUG
     InjectContainer.RegisterInstance <IStringEncrypter>(new PlainTextEncrypter());
     #else
     InjectContainer.RegisterInstance <IStringEncrypter>(new StringEncrypter());
     #endif
 }
예제 #8
0
        private void InjectService()
        {
            InjectContainer.RegisterType <IRabbitMQUrlProvider, AppsettingRabbitMQUrlProvider>();
            InjectContainer.RegisterType <ICommandPublisher, RabbitMQCommandPublisher>();
            InjectContainer.RegisterType <IRentalReadDBConnectionStringProvider, AppsettingRentalReadDBConnectionStringProvider>();
            InjectContainer.RegisterType <IRentalWriteDBConnectionStringProvider, AppsettingRentalWriteDBConnectionStringProvider>();
            InjectContainer.RegisterType <IRentalReportDataAccessor, RentalReportDataAccessor>();
            InjectContainer.RegisterType <ICommandTracker, SignalRCommandTracker>();

            InjectContainer.RegisterType <IConsulAPIUrlProvider, AppsettingConsulAPIUrlProvider>();
            InjectContainer.RegisterType <IServiceDiscovery, ConsulServiceDiscovery>();
        }
예제 #9
0
        private void InjectService()
        {
            InjectContainer.RegisterType <IRabbitMQUrlProvider, AppsettingRabbitMQUrlProvider>();
            InjectContainer.RegisterType <IPasswordHasher, PlainTextPasswordHasher>();
            InjectContainer.RegisterType <IIdentityReadDBConnectionStringProvider, AppsettingRepositoryReadDBConnectionStringProvider>();
            InjectContainer.RegisterType <IIdentityWriteDBConnectionStringProvider, AppsettingRepositoryWriteDBConnectionStringProvider>();
            InjectContainer.RegisterType <IIdentityReportDataAccessor, IdentityReportDataAccessor>();

            InjectContainer.RegisterType <IConsulAPIUrlProvider, AppsettingConsulAPIUrlProvider>();
            InjectContainer.RegisterType <IServiceDiscovery, ConsulServiceDiscovery>();
            InjectContainer.RegisterType <ICommandPublisher, RabbitMQCommandPublisher>();
        }
예제 #10
0
        private static void Injection()
        {
            var mappings = GetConfiguration().GetSection("diMappings").GetChildren();

            foreach (IConfigurationSection mapping in mappings)
            {
                var source = Assembly.Load(mapping["sAssembly"]).GetType(mapping["interface"]);
                var target = Assembly.Load(mapping["tAssembly"]).GetType(mapping["implementation"]);

                InjectContainer.RegisterType(source, target);
            }
        }
예제 #11
0
        private static void RegisterEventHandlers(string libraryName)
        {
            Func <Type, bool> isEventHandler = i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEventHandler <>);

            var commandHandlers = Assembly.Load(libraryName).GetExportedTypes()
                                  .Where(t => t.GetInterfaces().Any(isEventHandler))
                                  .ToList();

            var registerSource = commandHandlers.Select(h =>
            {
                return(new { FromType = h.GetInterfaces().First(isEventHandler), ToType = h });
            }).ToList();

            foreach (var r in registerSource)
            {
                InjectContainer.RegisterType(r.FromType, r.ToType);
            }
        }
        private void RegisterCommandHandlers()
        {
            Func <Type, bool> isCommandHandler = i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICommandHandler <>);

            var commandHandlers = typeof(ICommandHandler <>).Assembly.GetExportedTypes()
                                  .Where(t => t.GetInterfaces().Any(isCommandHandler))
                                  .ToList();

            var registerSource = commandHandlers.Select(h =>
            {
                return(new { FromType = h.GetInterfaces().First(isCommandHandler), ToType = h });
            }).ToList();

            foreach (var r in registerSource)
            {
                Logger.LogDebug(typeof(CommandBus), String.Format("Register Command Handler: {0}", r.ToType.FullName));
                InjectContainer.RegisterType(r.FromType, r.ToType);
            }
        }
 protected override void InjectLibraries()
 {
     InjectContainer.RegisterType <IDomainDataAccessor, DomainDbDataAccessor>();
     InjectContainer.RegisterType <IQueryDataAccessor, QueryDbDataAccessor>();
     RegisterCommandHandlers();
 }
예제 #14
0
 protected virtual void InjectCommonLibraries()
 {
     InjectContainer.RegisterType <IQueryService, QueryService>();
     InjectContainer.RegisterInstance <ICommandBus>(new CommandBus());
 }