public static void RegisterDependencies() { var container = new Container {Options = {DefaultScopedLifestyle = new WebRequestLifestyle()}}; // Container container.Register<IServiceProvider>(() => container); // Request (command/query) dispatcher container.Register<IRequestDispatcher, RequestDispatcher>(); // Command handlers container.Register(typeof (ICommandHandler<>), new[] {typeof (TabService).Assembly}); container.RegisterDecorator(typeof (ICommandHandler<>), typeof (ValidationDecoratorCommandHandler<>)); container.RegisterDecorator(typeof (ICommandHandler<>), typeof (LoggingDecoratorCommandHandler<>)); // Query handlers container.Register(typeof (IQueryHandler<,>), new[] {typeof (TabReadModel).Assembly}); // Validators container.RegisterSingleton(typeof (IValidator<>), typeof (CompositeValidator<>)); container.AppendToCollection(typeof (IValidator<>), typeof (DataAnnotationsValidator<>)); container.RegisterCollection(typeof (IValidator<>), typeof (MvcApplication).Assembly); // Data annotations validators container.Register(typeof (IValidationAttributeValidator<>), new[] {typeof (IValidationAttributeValidator<>).Assembly}); // Loggers container.RegisterSingleton<ILoggerFactory, NLogLoggerFactory>(); // Action filters container.RegisterCollection(typeof (IActionFilter<>), typeof (MvcApplication).Assembly); // Repository container.Register<IEventStore, InMemoryEventStore>(); // Aggregate factory container.Register<IAggregateFactory, AggregateFactory>(); // Event publisher container.Register<IEventPublisher>(() => new EventPublisher(type => container.GetAllInstances(type), container.GetInstance<ILoggerFactory>())); // Event handlers container.RegisterCollection(typeof (IEventSubscriber<>), new[] {typeof (TabReadModel).Assembly}); // View model database container.RegisterSingleton<IReadModelDatabase, InMemoryReadModelDatabase>(); // Verify container.Verify(); System.Web.Mvc.DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); System.Web.Mvc.GlobalFilters.Filters.Add(new ActionFilterDispatcher(type => container.GetAllInstances(type))); ServiceProvider = container; }
/// <summary> /// Adds the mapper profile. /// </summary> /// <param name="container">The container.</param> private void AddMapperProfile(Container container) { try { container.AppendToCollection(typeof(Profile), Lifestyle.Singleton.CreateRegistration(typeof(Profile), typeof(EntityMapperConfig), container)); } catch (Exception ex) { ex.ExceptionValueTracker(container); } }
public static void RegisterServices(Container container, ILoggerFactory loggerFactory) { container.Register<IUserIdProvider, PrincipalUserIdProvider>(); container.Register<MessageBusConnection>(); container.RegisterSingleton<ConnectionMapping>(); container.RegisterSingleton<MessageBusBroker>(); var resolver = new SimpleInjectorSignalRDependencyResolver(container); container.RegisterSingleton<IDependencyResolver>(resolver); container.RegisterSingleton<IConnectionManager>(() => new ConnectionManager(resolver)); container.RegisterSingleton<OverageHandler>(); container.RegisterSingleton<ThrottlingHandler>(() => new ThrottlingHandler(container.GetInstance<ICacheClient>(), userIdentifier => Settings.Current.ApiThrottleLimit, TimeSpan.FromMinutes(15))); container.AppendToCollection(typeof(Profile), typeof(ApiMappings)); }
public static void Setup() { var container = new Container(); var perRequest = new WebRequestLifestyle(); var dataAccessAssembly = typeof(CinemaContext).Assembly; var moviesAssembly = typeof(Seat).Assembly; var promotionsAssembly = typeof(Promotions.Promotion).Assembly; var applicationAssembly = typeof(RenamePromotionCommand).Assembly; var connectionString = ConfigurationManager.ConnectionStrings["DDDCinema"].ConnectionString; container.Register(() => new CinemaContext(connectionString), perRequest); container.Register(() => new PromotionsContext(connectionString), perRequest); container.Register(() => new InfrastructureContext(connectionString), perRequest); container.Register(() => new DDDCinemaReadonly(), perRequest); var userProviderRegistration = Lifestyle.Singleton.CreateRegistration<ContextUserProvider>(container); container.AddRegistration(typeof(ICurrentUserProvider), userProviderRegistration); container.AddRegistration(typeof(ContextUserProvider), userProviderRegistration); container.Register<IWinChanceCalculatorFactory, SimpleInjectorWinChanceCalculatorFactory>(Lifestyle.Singleton); foreach (var repositorType in dataAccessAssembly.GetExportedTypes() .Where(t => t.Name.Contains("Repository"))) { container.Register(repositorType.GetInterfaces().Single(), repositorType, perRequest); } container.RegisterDecorator(typeof(ICommandHandler<LoginCommand>), typeof(AuditingLoginCommandHandler)); container.RegisterDecorator(typeof(ICommandHandler<>), typeof(AuditingCommandHandler<>), p => !p.AppliedDecorators.Any(t => t.Name.Contains("Auditing"))); container.RegisterDecorator(typeof(ICommandHandler<>), typeof(CinemaTransactionalCommandHandler<>)); container.RegisterDecorator(typeof(ICommandHandler<>), typeof(PromotionTransactionalCommandHandler<>)); container.RegisterDecorator(typeof(ICommandHandler<>), typeof(InfrastructureTransactionalCommandHandler<>)); container.Register(typeof(ICommandHandler<>), new[] { applicationAssembly }); container.RegisterCollection(typeof(INotificationSender), new[] { moviesAssembly }); var registration = perRequest.CreateRegistration<SendNotificationWhenSeatTaken>(container); container.AppendToCollection(typeof(IDomainEventHandler<>), typeof(AuditOccurrenceEventHandler<>)); container.RegisterCollection(typeof(IDomainEventHandler<>), moviesAssembly, promotionsAssembly); container.RegisterDecorator(typeof(IDomainEventHandler<>), typeof(AuditingEventHandler<>), p => !p.ImplementationType.Name.Contains("Audit")); container.Register<List<INotificationSender>>(() => container.GetAllInstances<INotificationSender>().ToList(), perRequest); container.Register<ISheduler, SagaTimeoutSheduler>(perRequest); container.Register<IPromotionCodeGenerator, PromoCodeGenerator>(perRequest); DomainEventBus.Current = new SimpleInjectorEventBus(container); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); }