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}'"); } }
private void InjectService() { InjectContainer.RegisterType <IPasswordHasher, PlainTextPasswordHasher>(); InjectContainer.RegisterType <IIdentityReadDBConnectionStringProvider, AppsettingRepositoryReadDBConnectionStringProvider>(); InjectContainer.RegisterType <IIdentityWriteDBConnectionStringProvider, AppsettingRepositoryWriteDBConnectionStringProvider>(); InjectContainer.RegisterType <IIdentityReportDataAccessor, IdentityReportDataAccessor>(); }
private void InjectService() { InjectContainer.RegisterType <ILogDBConnectionStringProvider, AppsettingLogDBConnectionStringProvider>(); InjectContainer.RegisterType <ILogger, Logger>(); InjectContainer.RegisterType <IConsulAPIUrlProvider, AppsettingConsulAPIUrlProvider>(); InjectContainer.RegisterType <IServiceDiscovery, ConsulServiceDiscovery>(); }
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>(); }
public static void Register() { InjectContainer.RegisterType <ICommonService, CommonService>(); InjectContainer.RegisterType <ILogHelper, LogHelper>(); InjectContainer.RegisterType <IFileService, FileService>(); }
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>(); }
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 }
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>(); }
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>(); }
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); } }
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(); }
protected virtual void InjectCommonLibraries() { InjectContainer.RegisterType <IQueryService, QueryService>(); InjectContainer.RegisterInstance <ICommandBus>(new CommandBus()); }