Esempio n. 1
0
        // This method gets called by the runtime, but was manually introduced.
        // Use this method to configure injected services.
        public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider)
        {
            var env = serviceProvider.GetService <IHostingEnvironment>();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();

            var commandBus = serviceProvider.GetService <ICommandBus>() as FakeBus;

            if (commandBus != null)
            {
                var facilityCommandHandlers = serviceProvider.GetService <FacilityCommandHandlers>();
                commandBus.RegisterHandler <CreateFacilityCommand>(facilityCommandHandlers.Handle);
            }

            var eventPublisher = serviceProvider.GetService <IEventPublisher>() as FakeBus;

            if (eventPublisher != null)
            {
                eventPublisher.RegisterHandler <FacilityCreatedEvent>((e) => {
                    System.Console.WriteLine($"Created facility({e.FacilityId} - {e.FacilityName})");

                    JsonSerializerSettings settings = new JsonSerializerSettings {
                        TypeNameHandling = TypeNameHandling.All
                    };

                    var e_serialized = JsonConvert.SerializeObject(e, settings);

                    Event e_deserialized = JsonConvert.DeserializeObject <Event>(e_serialized, settings);

                    Facility f = new Facility();
                    f.AsDynamic().Apply(e_deserialized);

                    System.Console.WriteLine($"Serialized and then deserialized {f.Id}");
                });
            }
        }