Example #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, CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(new ExceptionHandlerOptions
                {
                    ExceptionHandler = async context =>
                    {
                        context.Response.ContentType = "text/plain";
                        await context.Response.WriteAsync("Welcome to the error page.");
                    }
                });
            }
            cityInfoContext.EnsureSeedDataForContext();
            app.UseStatusCodePages();
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>().ReverseMap();
                cfg.CreateMap <Entities.City, Models.CityDto>().ReverseMap();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>().ReverseMap();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForCreationDto>().ReverseMap();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>().ReverseMap();
            });

            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // sends exceptions to logging framework
                app.UseExceptionHandler();
            }

            cityInfoContext.EnsureSeedDataForContext();

            // returns status codes in response body so visible in browsers
            app.UseStatusCodePages();

            // MVC middleware
            app.UseMvc();

            //app.Run(context =>
            //{
            //    throw new Exception("Bad");
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            // These two were already added in CreateDefaultBuilder from .NetCore 2.2
            // No need to add it again
            // loggerFactory.AddConsole();
            // loggerFactory.AddDebug();

            // loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            loggerFactory.AddNLog();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }
            cityInfoContext.EnsureSeedDataForContext();
            app.UseStatusCodePages();
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });
            app.UseMvc();
            // app.Run(async (context) =>
            // {
            //     await context.Response.WriteAsync("Hello World!");
            // });
        }
Example #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            loggerFactory.AddNLog();

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

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <City, Models.CityDto>();
                cfg.CreateMap <PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseMvc();
        }
Example #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();


            app.UseMvc();

            //app.Run((context) =>
            //{
            //    throw new Exception("Exception occured");
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            loggerFactory.AddDebug();

            loggerFactory.AddNLog();

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

            cityInfoContext.EnsureSeedDataForContext();
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
            app.UseStatusCodePages();
            AutoMapper.Mapper.Initialize(cfg => {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointOfInterestDto>();

                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfIntrestDto>();

                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfIntrestDto, Entities.PointOfInterest>();

                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();

                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();

                //cfg.CreateMap<List<Entities.PointOfInterest>, List<Models.PointOfIntrestDto>>();
            });
            app.UseMvc();
            //app.UseMvcWithDefaultRoute();
        }
Example #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();

            loggerFactory.AddDebug();

            //loggerFactory.AddProvider(new NLogLoggerProvider());
            loggerFactory.AddNLog();

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

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            ConfigureMappings();

            app.UseMvc();
        }
Example #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            loggerFactory.AddNLog();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseHttpsRedirection();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                // database -> dto
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();

                // dto -> database
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
            });

            app.UseMvc();

            app.UseStatusCodePages();
        }
Example #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            app.UseMvc();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Hello World!");
                });
            });

            app.UseOpenApi();
            app.UseSwaggerUi3();
        }
Example #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory, CityInfoContext cityInfoContext)
        {
            loggerfactory.AddConsole();
            loggerfactory.AddDebug();
            // loggerfactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            loggerfactory.AddNLog();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            // app.Run((contex) => { throw new Exception("Example exception"); });
            else
            {
                app.UseHsts();
            }
            cityInfoContext.EnsureSeedDataForContext();
            //Format status code

            app.UseStatusCodePages();
            AutoMapper.Mapper.Initialize(c => {
                c.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                c.CreateMap <Entities.City, Models.CityDto>();
                c.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                c.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                c.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                c.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseHttpsRedirection();
            app.UseMvc();
        }
Example #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDTO>();
                cfg.CreateMap <Entities.City, Models.CitiesDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointsOfInterestDTO>();
            });

            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();
            loggerFactory.AddDebug(LogLevel.Information);

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

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            //Use AutoMapper library (initialize the mappings you're planning to need)
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestUpdateDto>();
            });

            app.UseMvc();
        }
Example #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();

            loggerFactory.AddDebug();

            loggerFactory.AddNLog();

            //loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            cityInfoContext.EnsureSeedDataForContext();
            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
            });


            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages(); // I enabled it to see status code text sample pages in browser :)

            // Using AutoMapper to automaticly map entities to my dto objects.s
            AutoMapper.Mapper.Initialize(cfg => {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestsDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseMvc();
        }
Example #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            //loggerFactory.AddNLog(); - 7/9/18 - Not supported by 2.0

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

            // seed the database
            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            // database row to model information (return only the data we need)
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseMvc();
        }
Example #16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            loggerFactory.AddNLog();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //else
            //{
            //    app.UseExceptionHandler();
            //}

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <City, CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <City, CityDto>();
                cfg.CreateMap <PointOfInterest, PointOfInterestDto>();
                cfg.CreateMap <PointOfInterestForCreationDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterestForUpdateDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterest, PointOfInterestForUpdateDto>();
            });

            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #17
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();

            loggerFactory.AddDebug();

            //loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            loggerFactory.AddNLog();

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

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            app.UseMvc();

            //app.Run((context) =>
            //{
            //    throw new Exception("Example exception");
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #18
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            //loggerFactory.AddConsole();
            //loggerFactory.AddDebug();
            loggerFactory.AddNLog();

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

            // Add seed data to database.
            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();

                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();

                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseMvc();
        }
Example #19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                // cfg.CreateMap<Entities.PointOfInterest, Models.PointOfInterestForCreationDto>()
                // .ForMember(x => x.Id, opt => opt.Ignore());
                // cfg.CreateMap<Entities.City, Models.CityWithoutPointsOfInterestDto>();
                // cfg.CreateMap<Entities.City, Models.CityDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>()
                .ForMember(dest => dest.Id, opt => opt.Ignore());
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>()
                .ForMember(dest => dest.Id, opt => opt.Ignore());
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseMvc();
        }
Example #20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            // AddDebug causes any debug errors to log to the 'Debug' output window
            // loggerFactory.AddConsole();
            loggerFactory.AddDebug();
            loggerFactory.AddNLog();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // adds an exception handler page when not in dev environment
                app.UseExceptionHandler();
            }

            cityInfoContext.EnsureSeedDataForContext();

            // Status Code Pages middleware
            app.UseStatusCodePages();

            // Use Automapper package to create a map from endpoint of entities to the dtos we are returning from API actions
            AutoMapper.Mapper.Initialize(cfg =>
            {
                // mapping for GET requests
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                // CityDto includes a list of interests, so it should also map from POI to it's Dto for City>CityDto to work
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();

                // mapping for creating objects (POST)
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();

                //mapping for updating a resource (PUT)
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();

                // mapping for partial updating (PATCH)
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseMvc();

            // Uncomment below block to see the exception handler page
            //app.Run((context) =>
            //{
            //    throw new Exception("Example exception");
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            //loggerFactory.AddConsole();
            //loggerFactory.AddDebug();

            //loggerFactory.AddProvider(new NLogLoggerProvider());
            loggerFactory.AddNLog();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/error");
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            app.UseMvc();

            Mapper.Initialize(cfg =>
            {
                // Way 1
                cfg.CreateMap <City, CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <City, CityDto>();
                cfg.CreateMap <PointOfInterestForCreationDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterest, PointOfInterestDto>();
                cfg.CreateMap <PointOfInterestForUpdateDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterest, PointOfInterestForUpdateDto>();
                // cfg.CreateMap<Entities.PointOfInterest, Models.PointOfInterestDto>(); // Don't need for AutoMapper 7.x.x
                // Way 2
                //cfg.CreateMap(typeof(City), typeof(CityWithoutPointsOfInterestDto));
            });

            // Convention-based routing
            // Typically for using MVC framework to build a web application with HTML-returning views.
            // For web api, using attribute-based routing.
            //app.UseMvc(config =>
            //{
            //    config.MapRoute(
            //        name: "Default",
            //        template: "{controller}/{action}/{id?}",
            //        defaults: new { controller = "Home", action = "Index" });
            //});

            //app.Run(async (context) =>
            //{
            //    throw new Exception("example exception");
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #22
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            //Long way to add the nLogger extension to loggerFactory
            //loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());

            //Short-cut. Now we're also logging out to a file.
            loggerFactory.AddNLog();

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

            //Seed the database with data
            cityInfoContext.EnsureSeedDataForContext();

            //Create mappings from the application's DTOs to their respective entity classes returned from Sql.
            AutoMapper.Mapper.Initialize(cfg =>
            {
                //Syntax is CreateMap(SourceType, DestinationType). In other words: From an Entity to a DTO object
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();

                //You can create multiple mappings. In this case, getting a city back should match to both the CityDto and the CityWithoutPointsOfInterestDto
                cfg.CreateMap <Entities.City, Models.CityDto>();

                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();

                //For POST (i.e. creating a POI, the arguments are reveresed because the Entities.POI is the destination type).
                cfg.CreateMap <Models.PointOfInterestForCreation, Entities.PointOfInterest>();

                //For updating with PUT
                cfg.CreateMap <Models.PointOfInterestForUpdate, Entities.PointOfInterest>();

                //For updating with Patch. We need the other way around since we're mapping an entity to a POIForUpdate dto.
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdate>();
            });

            // Show Error pages when the consuming browser gets an error (e.g. instead of a silent 404 error)
            //app.UseStatusCodePages();
            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #23
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext) //LD STEP29 be sure that the configuration method accept the context
        {
            //loggerFactory.AddConsole();

            //LD STEP22
            loggerFactory.AddDebug();

            //loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            //loggerFactory.AddNLog();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //LD friendly exeption page
                //app.UseExceptionHandler();
            }

            ////LD STEP1
            //LD STEP29
            cityInfoContext.EnsureSeedDataForContext();

            //LD STEP9
            app.UseStatusCodePages();

            //LD STEP35
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            //LD STEP2 we are adding MVC after the exception handler
            app.UseMvc();

            //app.Run((context) =>
            //{
            //    throw new Exception("Example exception");
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #24
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            // No need to add these loggers in ASP.NET Core 2.0: the call to WebHost.CreateDefaultBuilder(args)
            // in the Program class takes care of that.
            //loggerFactory.AddConsole();
            //loggerFactory.AddDebug();

            // Use NLog
            loggerFactory.AddNLog();

            // Display detailed exception page, when the environment in Project properties is set to Development
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }

            // Seed data, if required
            cityInfoContext.EnsureSeedDataForContext();

            // Use simple status code page for HTTP response
            app.UseStatusCodePages();

            // Use Automapper to map entity objects and DTOs
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
            });

            app.UseMvc();

            //app.Run((context) =>
            //{
            //    throw new Exception("Example exception");
            //});

            // This will always return Hello World for HTTP response
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            cityInfoContext.EnsureSeedDataForContext();
            app.UseMvc();

            // app.Run(async (context) =>
            // {
            //     await context.Response.WriteAsync("Hello World!");
            // });
        }
Example #26
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            loggerFactory.AddConsole();
            cityInfoContext.EnsureSeedDataForContext();
            loggerFactory.AddDebug();
            loggerFactory.AddNLog();

            app.UseMvc();
        }
Example #27
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();

            loggerFactory.AddDebug();

            //loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            loggerFactory.AddNLog();


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

            cityInfoContext.EnsureSeedDataForContext();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Model.CityWithoutPointOfInterestDto>();
                cfg.CreateMap <Entities.City, Model.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Model.PointOfInterestDto>();
                cfg.CreateMap <Model.PointOfInterestDto, Entities.PointOfInterest>();
                cfg.CreateMap <Model.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Model.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Model.PointOfInterestForUpdateDto>();
            });

            app.UseStatusCodePages();

            app.UseMvc();

            /*
             * app.UseMvc(config =>
             * {
             *  config.MapRoute(
             *      name: "Default",
             *      template: "{controller}/{action}/{id?}",
             *      defaults: new { controller = "Home", action = "Index" }
             *      );
             * });
             */


            //    app.Run(async (context) =>
            //    {
            //        await context.Response.WriteAsync("Hello World!");
            //    });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            // No need to add these loggers in ASP.NET Core 2.0: the call to WebHost.CreateDefaultBuilder(args)
            // in the Program class takes care of that.

            //loggerFactory.AddConsole();
            //loggerFactory.AddDebug();

            //loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            loggerFactory.AddNLog();

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

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Models.CityDto, Entities.City>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseCors(builder => builder.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
            app.UseMvc();

            //app.Run((context) =>
            //{
            //    throw new Exception("Example exception");
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #29
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();

            loggerFactory.AddDebug();

            #region NLog
            //add NLog to .NET Core
            loggerFactory.AddNLog();

            ////Enable ASP.NET Core features (NLog.web) - only needed for ASP.NET Core users
            //app.AddNLogWeb();

            //needed for non-NETSTANDARD platforms: configure nlog.config in your project root. NB: you need NLog.Web.AspNetCore package for this.
            env.ConfigureNLog(Path.Combine(env.ContentRootPath, "nlog.config"));
            #endregion

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

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <City, CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <City, CityDto>();
                cfg.CreateMap <PointOfInterest, PointOfInterestDto>();
                cfg.CreateMap <PointOfInterestDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterestForCreationDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterestForUpdateDto, PointOfInterest>();
                cfg.CreateMap <PointOfInterest, PointOfInterestForUpdateDto>();
            });
            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #30
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            loggerFactory.AddConsole();

            loggerFactory.AddDebug();

            // loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            // these third party logging library nicely integrate with asp.net core app.
            loggerFactory.AddNLog();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage(); // middle ware added in development environment
            }
            else
            {
                app.UseExceptionHandler();
            }

            cityInfoContext.EnsureSeedDataForContext();// using extension to seed data(have to do that in ef core as it is known github issue).

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointsOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointsOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointsOfInterestForUpdateDto>();
            });

            // add mvc to http request pipeline AFTER exception
            app.UseMvc();

            //app.Run((context) =>
            //{
            //    throw new Exception(("Example exception"));
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }