Exemple #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,
                              ILoggerFactory loggerFactory,
                              SprotifyContext sprotifyContext)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        // ensure generic 500 status code on fault.
                        context.Response.StatusCode = 500;
                        await context
                        .Response.WriteAsync("An unexpected fault happened. Try again later.");
                    });
                });
            }

            // use default files (like index.html for root)
            app.UseDefaultFiles();

            // allow serving up files from wwwroot (eg images)
            app.UseStaticFiles();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.Playlist, Models.Playlist>();
                cfg.CreateMap <Entities.Playlist, Models.PlaylistWithSongs>();
                cfg.CreateMap <Entities.Song, Models.Song>();
                cfg.CreateMap <Models.SongForCreation, Entities.Song>();
                cfg.CreateMap <Models.SongForUpdate, Entities.Song>().ReverseMap();
                cfg.CreateMap <Entities.Song, Models.Song>();
            });

            // test for, and if required, migrate the DB
            sprotifyContext.Database.Migrate();

            // ensure seed data
            sprotifyContext.EnsureSeedDataForContext();

            app.UseMvc();
        }
Exemple #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,
                              ILoggerFactory loggerFactory,
                              SprotifyContext sprotifyContext)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        // ensure generic 500 status code on fault.
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync("An unexpected fault happened. Try again later.");
                    });
                });
            }

            // use default files (like index.html for root)
            app.UseDefaultFiles();

            // allow serving up files from wwwroot (eg images)
            app.UseStaticFiles();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.Playlist, Models.Playlist>();
                cfg.CreateMap <Services.Models.PlaylistWithSongs, Models.PlaylistWithSongs>();
                cfg.CreateMap <Models.PlaylistForCreation, Entities.Playlist>();
                cfg.CreateMap <Entities.Song, Models.Song>();
                cfg.CreateMap <Services.Models.SongWithPlaylistInfo, Models.SongInPlaylist>();
                cfg.CreateMap <Models.SongForCreation, Entities.Song>();
                cfg.CreateMap <Models.SongForUpdate, Entities.Song>().ReverseMap();
                cfg.CreateMap <Entities.User, Models.User>();
                cfg.CreateMap <Entities.User, Models.UserWithPlaylists>();

                cfg.CreateMap <Models.SongForPlaylist, Entities.PlaylistSong>();

                cfg.CreateMap <Entities.PlaylistSong, Models.SongInPlaylist>()
                .ForMember(x => x.Id, opt => opt.MapFrom(src => src.SongId))
                .ForMember(x => x.Title, opt => opt.MapFrom(src => src.Song.Title))
                .ForMember(x => x.Band, opt => opt.MapFrom(src => src.Song.Band))
                .ForMember(x => x.Duration, opt => opt.MapFrom(src => src.Song.Duration));
            });

            // test for, and if required, migrate the DB
            sprotifyContext.Database.Migrate();

            // ensure seed data
            sprotifyContext.EnsureSeedDataForContext();

            app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority            = "https://localhost:44375/",
                RequireHttpsMetadata = true,
                ApiName = "sprotifyapi"
            });

            app.UseMvc();
        }