상속: IEventEmitter
예제 #1
0
        public DomainRegistry()
        {
            var config = Fluently.Configure()
                .Database(PostgreSQLConfiguration.PostgreSQL82
                    .ConnectionString(c => c.FromAppSetting("lender_db"))
                    .DefaultSchema(ConfigurationManager.AppSettings["lender_db_schema"])
                )
                .CurrentSessionContext<ThreadStaticSessionContext>()
                .Mappings(m =>
                    m.FluentMappings
                        .AddFromAssemblyOf<OpenedLibraryMap>()
                        .AddFromAssemblyOf<LibraryBookMap>()
                        .AddFromAssemblyOf<AuthenticatedUserMap>()
                )
                .BuildConfiguration()
                ;

            For<NHibernate.Cfg.Configuration>()
                .Singleton()
                .Use(config)
                ;

            For<NHibernate.ISessionFactory>()
                .Singleton()
                .Use(config.BuildSessionFactory())
                ;

            For<NHibernate.ISession>()
                .Use(c => c.GetInstance<NHibernateUnitOfWork>().CurrentSession)
                ;

            For<IRepository>()
                .AlwaysUnique()
                .Use<NHibernateRepository>()
                ;

            Scan(scanner =>
            {
                scanner.AssemblyContainingType<Command>();
                scanner.AssemblyContainingType<AddBookToLibrary>();
                scanner.AssemblyContainingType<SearchForLibrary>();
                scanner.ConnectImplementationsToTypesClosing(typeof(ICommandHandler<>));
                scanner.ConnectImplementationsToTypesClosing(typeof(IQueryHandler<>));
                scanner.ConnectImplementationsToTypesClosing(typeof(IMessageHandler<>));
                scanner.ConnectImplementationsToTypesClosing(typeof(IAuthenticatedMessageHandler<>));
                scanner.ConnectImplementationsToTypesClosing(typeof(IAuthenticatedCommandHandler<>));
                scanner.ConnectImplementationsToTypesClosing(typeof(AuthenticatedCommandHandler<>));
                scanner.ConnectImplementationsToTypesClosing(typeof(IAuthenticatedMessageHandler<>));
                scanner.ConnectImplementationsToTypesClosing(typeof(IEventHandler<>));
            });

            For<IEventRepository>()
                .Use(c => c.GetInstance<EventStoreUnitOfWork>().EventRepository)
                ;

            For<Func<Guid>>()
                .Use(new Func<Guid>(SequentialGuid.NewGuid));

            var eventEmitter = new InMemoryEventEmitter();

            For<IEventEmitter>()
                .Singleton()
                .Use(eventEmitter);

            For<InMemoryEventEmitter>()
                .Singleton()
                .Use(eventEmitter);

            For<BlockingCollection<Event>>()
                .Singleton()
                .Use(new BlockingCollection<Event>())
                ;

            For<Func<Type, IEnumerable<IEventHandler>>>()
                .Use<Func<Type, IEnumerable<IEventHandler>>>(context => eventType => GetEventHandlers(context, eventType));

            For<IMessageHandler<SearchForLibrary>>()
                .AlwaysUnique()
                .Use<SearchForLibraryHandler>();

            For<EventDispatcher>()
                .AlwaysUnique()
                .Use<EventDispatcher>();

            For<EventHandlerProvider>()
                .AlwaysUnique()
                .Use<EventHandlerProvider>();

            string jwtSecret = ConfigurationManager.AppSettings["jwt_secret"];

            For<Tokeniser>()
                .AlwaysUnique()
                .Use<Tokeniser>()
                .Ctor<string>()
                .Is(jwtSecret);

            For<IAuthenticationCallbackProvider>()
                .AlwaysUnique()
                .Use<AuthCallbackProvider>();

            For<IUserMapper>()
                .AlwaysUnique()
                .Use<UserMapper>();
        }
예제 #2
0
 public EventDispatcher(InMemoryEventEmitter eventEmitter, EventHandlerProvider eventHandlerProvider)
 {
     this.eventEmitter         = eventEmitter;
     this.eventHandlerProvider = eventHandlerProvider;
 }
예제 #3
0
 public EventDispatcher(InMemoryEventEmitter eventEmitter, EventHandlerProvider eventHandlerProvider)
 {
     this.eventEmitter = eventEmitter;
     this.eventHandlerProvider = eventHandlerProvider;
 }