Skip to content

Commit

Permalink
updated from .net core 2.2 to 3.1 and bumped package versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlsailrunner committed Jul 16, 2020
1 parent d6d9d14 commit 238ea80
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 59 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@
/AspNetCore-Effective-Logging/BookClub.Logic/obj
/AspNetCore-Effective-Logging/BookClub.Infrastructure/bin/Debug/netstandard2.0
/AspNetCore-Effective-Logging/BookClub.Infrastructure/obj
/AspNetCore-Effective-Logging/BookClub.API/bin/Debug/netcoreapp3.1
/AspNetCore-Effective-Logging/BookClub.Data/bin/Debug/netstandard2.1
/AspNetCore-Effective-Logging/BookClub.Entities/bin/Debug/netstandard2.1
/AspNetCore-Effective-Logging/BookClub.Infrastructure/bin/Debug/netstandard2.1
/AspNetCore-Effective-Logging/BookClub.Logic/bin/Debug/netstandard2.1
/AspNetCore-Effective-Logging/BookClub.UI/bin/Debug/netcoreapp3.1
17 changes: 6 additions & 11 deletions AspNetCore-Effective-Logging/BookClub.API/BookClub.API.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RootNamespace>BookClub.API</RootNamespace>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.7.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NLog.Targets.ElasticSearch" Version="6.1.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.4" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="NLog.Targets.ElasticSearch" Version="7.3.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.2" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
</ItemGroup>

<ItemGroup>
Expand Down
53 changes: 35 additions & 18 deletions AspNetCore-Effective-Logging/BookClub.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BookClub.Infrastructure.Middleware;
using BookClub.Data;
using BookClub.Logic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using BookClub.Infrastructure.Filters;
using BookClub.Infrastructure;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;

namespace BookClub.API
{
public class Startup
{
private readonly ILoggerFactory _loggerFactory;
//private readonly ILoggerFactory _loggerFactory;

public Startup(IConfiguration configuration, ILoggerFactory loggerFactory)
//public Startup(IConfiguration configuration, ILoggerFactory loggerFactory)
public Startup(IConfiguration configuration)
{
Configuration = configuration;
_loggerFactory = loggerFactory;
//_loggerFactory = loggerFactory;
}

public IConfiguration Configuration { get; }
Expand All @@ -53,17 +54,28 @@ public void ConfigureServices(IServiceCollection services)
services.AddSwaggerGen(c =>
{
var oauthScopeDic = new Dictionary<string, string> { {"api", "Access to the Book Club API"} };
c.SwaggerDoc("v1", new Info { Title = "Book Club API", Version = "v1" });
c.AddSecurityDefinition("oauth2", new OAuth2Scheme
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Book Club API", Version = "v1" });
c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Type = "oauth2",
Flow = "implicit",
AuthorizationUrl = "https://demo.identityserver.io/connect/authorize",
Scopes = oauthScopeDic
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
Implicit = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri("https://demo.identityserver.io/connect/authorize"),
Scopes = oauthScopeDic
}
}
});
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ "oauth2", new [] { "api" }}
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "oauth2"}
},
oauthScopeDic.Keys.ToArray()
}
});
});

Expand All @@ -73,18 +85,18 @@ public void ConfigureServices(IServiceCollection services)
.RequireAuthenticatedUser();
options.Filters.Add(new AuthorizeFilter(builder.Build()));
options.Filters.Add(typeof(TrackActionPerformanceFilter));
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
});
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseApiExceptionHandler(options =>
{
options.AddResponseDetails = UpdateApiErrorResponse;
options.DetermineLogLevel = DetermineLogLevel;
});
app.UseHsts();

app.UseStaticFiles();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
Expand All @@ -94,7 +106,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseAuthentication();

app.UseHttpsRedirection();
app.UseMvc();
app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}

private LogLevel DetermineLogLevel(Exception ex)
Expand All @@ -109,7 +126,7 @@ private LogLevel DetermineLogLevel(Exception ex)

private void UpdateApiErrorResponse(HttpContext context, Exception ex, ApiError error)
{
if (ex.GetType().Name == typeof(SqlException).Name)
if (ex.GetType().Name == nameof(SqlException))
{
error.Detail = "Exception was a database exception!";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>BookClub.Data</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="1.60.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.6" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 2 additions & 9 deletions AspNetCore-Effective-Logging/BookClub.Logic/BookLogic.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.Net.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
using BookClub.Data;
using BookClub.Logic.Models;
using BookClub.Entities;
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
using System.Net.Http.Json;

namespace BookClub.Logic
{
Expand Down Expand Up @@ -54,14 +54,7 @@ private async Task<BookModel> GetBookModelFromBook(Book book)
try
{
_logger.LogDebug("Calling Google API with ISBN {ISBN} and uri {GoogleUri}", book.Isbn, uri);
var response = await httpClient.GetAsync(uri);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Failed in Google API for ISBN: {book.Isbn} - responseCode = " +
$"{response.StatusCode}");
}
var content = await response.Content.ReadAsStringAsync();
var bookResponse = JsonConvert.DeserializeObject<GoogleBookResponse>(content);
var bookResponse = await httpClient.GetFromJsonAsync<GoogleBookResponse>(uri);

var thisBook = bookResponse?.Items?.FirstOrDefault();
if (thisBook != null)
Expand Down
11 changes: 5 additions & 6 deletions AspNetCore-Effective-Logging/BookClub.UI/BookClub.UI.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RootNamespace>BookClub.UI</RootNamespace>
<UserSecretsId>64a55203-6024-41a2-9efd-914e7fb0dbd5</UserSecretsId>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="NLog.Targets.ElasticSearch" Version="6.1.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.6" />
<PackageReference Include="NLog.Targets.ElasticSearch" Version="7.3.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.2" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace BookClub.UI.Pages
Expand Down
15 changes: 9 additions & 6 deletions AspNetCore-Effective-Logging/BookClub.UI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -64,17 +62,18 @@ public void ConfigureServices(IServiceCollection services)
};
});

services.AddMvc(config =>
services.AddRazorPages();
services.AddControllers(config =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
config.Filters.Add(new AuthorizeFilter(policy));
//config.Filters.Add(typeof(TrackPagePerformanceFilter));
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
});
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseExceptionHandler("/Error");
app.UseHsts();
Expand All @@ -86,7 +85,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseMvc();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}

private ClaimsPrincipal TransformClaims(ClaimsPrincipal principal)
Expand Down

0 comments on commit 238ea80

Please sign in to comment.