Skip to content

Commit

Permalink
#115 - Use WebHostEnvironment.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Mar 24, 2020
1 parent b9c964d commit 91d7c18
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Recollections.Api/Accounts/AccountsStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ private static void EnsureDatabase(IServiceCollection services)
}
}

public void ConfigureAuthentication(IApplicationBuilder app, IHostingEnvironment env)
public void ConfigureAuthentication(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseAuthentication();
app.UseAuthorization();
}
}
}
1 change: 1 addition & 0 deletions src/Recollections.Api/Recollections.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="ExifLib.Standard" Version="1.7.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Neptuo" Version="6.0.1" />
Expand Down
30 changes: 19 additions & 11 deletions src/Recollections.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Neptuo;
using Microsoft.Extensions.Hosting;
using Neptuo.Recollections.Accounts;
using Neptuo.Recollections.Entries;

Expand All @@ -17,11 +16,11 @@ namespace Neptuo.Recollections

public class Startup
{
private readonly IHostingEnvironment environment;
private readonly IWebHostEnvironment environment;
private readonly AccountsStartup accountsStartup;
private readonly EntriesStartup entriesStartup;

public Startup(IConfiguration configuration, IHostingEnvironment environment)
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
{
Ensure.NotNull(environment, "environment");
this.environment = environment;
Expand All @@ -35,23 +34,34 @@ public Startup(IConfiguration configuration, IHostingEnvironment environment)
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<PathResolver>(ResolvePath);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

services
.AddRouting(options => options.LowercaseUrls = true)
.AddControllers()
.AddNewtonsoftJson();

accountsStartup.ConfigureServices(services);
entriesStartup.ConfigureServices(services);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
if (env.IsDevelopment())
if (environment.IsDevelopment())
app.UseDeveloperExceptionPage();
else
app.UseStatusCodePages();

app.UseRouting();

UseCors(app);

accountsStartup.ConfigureAuthentication(app, env);
accountsStartup.ConfigureAuthentication(app, environment);

app.UseMvc();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health");
endpoints.MapControllers();
});
}

private static void UseCors(IApplicationBuilder app)
Expand All @@ -68,8 +78,6 @@ private static void UseCors(IApplicationBuilder app)
p.AllowAnyHeader();
p.SetPreflightMaxAge(TimeSpan.FromMinutes(10));
});

app.UseHealthChecks("/health");
}
}
}

0 comments on commit 91d7c18

Please sign in to comment.