Skip to content

Commit 205b16d

Browse files
author
Сергей Трегуб
committed
Make the project compatible with .net 6
1 parent d3d8b06 commit 205b16d

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

ProjectTemplates/ReferenceProject/Startup.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.AspNetCore.Builder;
66
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
77
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Hosting.Server.Features;
89
using Microsoft.AspNetCore.Http;
910
using Microsoft.AspNetCore.Mvc;
1011
using Microsoft.AspNetCore.Mvc.Infrastructure;
@@ -20,7 +21,9 @@
2021
using ReferenceProject.Filters;
2122
using ReferenceProject.Modules;
2223
using Serilog;
24+
using System;
2325
using System.IO;
26+
using System.Linq;
2427
using System.Text.Json;
2528
using System.Text.Json.Serialization;
2629

@@ -76,13 +79,12 @@ public void ConfigureServices(IServiceCollection services)
7679
})
7780
.AddJsonOptions(options =>
7881
{
79-
options.JsonSerializerOptions.IgnoreNullValues = true;
82+
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
8083
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
8184
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
8285
options.JsonSerializerOptions.WriteIndented = HostEnvironment.IsDevelopment();
8386
})
84-
.AddApiExplorer()
85-
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
87+
.AddApiExplorer();
8688

8789
services
8890
.AddAutoMapper(typeof(Startup)) // Check out Configuration/AutoMapperProfiles/DefaultProfile to do actual configuration. See: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#automapper
@@ -163,6 +165,12 @@ public void Configure(IApplicationBuilder app, ILogger<Startup> logger)
163165
});
164166

165167
logger.LogInformation("Server configuration is completed");
168+
var addr = app.ServerFeatures.Get<IServerAddressesFeature>().Addresses.FirstOrDefault();
169+
if (!string.IsNullOrWhiteSpace(addr))
170+
{
171+
var uri = new Uri(new Uri(addr), "swagger");
172+
logger.LogInformation("Open {uri} to browse the server API", uri);
173+
}
166174
}
167175
}
168176
}

0 commit comments

Comments
 (0)