예제 #1
0
        protected override void ConfigureApplicationContainer(IContainer existingContainer)
        {
            // Perform registation that should have an application lifetime
            ApplicationBootstrapper.Init();

            var documentStore = new DocumentStore
            {
                Url             = "http://localhost:8080",
                DefaultDatabase = "Todo"
            };

            documentStore.Conventions.FindTypeTagName = type =>
            {
                if (typeof(Domain.IEvent).IsAssignableFrom(type))
                {
                    return(type.Name);
                }

                //Crude way of making the State id's a little bit prettier
                if (type.Name.EndsWith("State"))
                {
                    return(Inflector.Pluralize(type.Name.Remove(type.Name.LastIndexOf("State", StringComparison.InvariantCulture), 5)));
                }

                return(DocumentConvention.DefaultTypeTagName(type));
            };

            documentStore.Initialize();

            existingContainer.Configure(cfg =>
            {
                cfg.For <IDocumentStore>().Use(documentStore).Singleton();
                cfg.Scan(scanner =>
                {
                    scanner.AssemblyContainingType <CreateTodoItem>();
                    scanner.AssemblyContainingType <IMediator>();
                    scanner.AddAllTypesOf(typeof(IRequestHandler <,>));
                    scanner.AddAllTypesOf(typeof(IEventHandler <>));
                    scanner.AddAllTypesOf(typeof(IPreRequestHandler <>));
                    scanner.AddAllTypesOf(typeof(IPostRequestHandler <,>));
                    scanner.WithDefaultConventions();
                });

                cfg.For <IDocumentSession>()
                .Use(ctx => ctx.GetInstance <IDocumentStore>()
                     .OpenSession());

                cfg.For <IManageUnitOfWork>()
                .Use <RavenDbUnitOfWork>();

                cfg.For(typeof(IRequestHandler <,>))
                .DecorateAllWith(typeof(MediatorPipeline <,>));

                cfg.For <ITodoItemRepository>().Use <TodoItemRepository>();
            });
        }