Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = true
                });
            }
            else
            {
                app.UseDeveloperExceptionPage();
                //app.UseExceptionHandler("/Home/Error");
            }

            // wireup
            var trailerAggregate = app.ApplicationServices.GetService <TrailerAggregate>();
            var relayNotifyer    = app.ApplicationServices.GetService <SmsNotifyer>();
            var readmodel        = app.ApplicationServices.GetService <IScheduleQueries>();
            var eventStore       = app.ApplicationServices.GetService <IEventStore>();

            // ladda readmodel för scheduler, en egen dispatcher
            var dispatcher = new MessageDispatcher(eventStore);

            dispatcher.AddSubscriberFor <TrailerBookedEvent>((Scheduler)readmodel);
            dispatcher.AddSubscriberFor <TrailerBookingCanceledEvent>((Scheduler)readmodel);
            var trailerEvents = eventStore.LoadEventsFor <object>(Constants.TrailerId);

            dispatcher.PublishEvents(trailerEvents);

            var messageDispatcher = app.ApplicationServices.GetService <IMessageDispatcher>();

            messageDispatcher.ScanInstance(trailerAggregate);
            messageDispatcher.ScanInstance(relayNotifyer);
            messageDispatcher.ScanInstance(readmodel);



            app.UseStaticFiles();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }