|
5 | 5 | using Microsoft.AspNetCore.Builder; |
6 | 6 | using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
7 | 7 | using Microsoft.AspNetCore.Hosting; |
| 8 | +using Microsoft.AspNetCore.Hosting.Server.Features; |
8 | 9 | using Microsoft.AspNetCore.Http; |
9 | 10 | using Microsoft.AspNetCore.Mvc; |
10 | 11 | using Microsoft.AspNetCore.Mvc.Infrastructure; |
|
20 | 21 | using ReferenceProject.Filters; |
21 | 22 | using ReferenceProject.Modules; |
22 | 23 | using Serilog; |
| 24 | +using System; |
23 | 25 | using System.IO; |
| 26 | +using System.Linq; |
24 | 27 | using System.Text.Json; |
25 | 28 | using System.Text.Json.Serialization; |
26 | 29 |
|
@@ -76,13 +79,12 @@ public void ConfigureServices(IServiceCollection services) |
76 | 79 | }) |
77 | 80 | .AddJsonOptions(options => |
78 | 81 | { |
79 | | - options.JsonSerializerOptions.IgnoreNullValues = true; |
| 82 | + options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; |
80 | 83 | options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); |
81 | 84 | options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; |
82 | 85 | options.JsonSerializerOptions.WriteIndented = HostEnvironment.IsDevelopment(); |
83 | 86 | }) |
84 | | - .AddApiExplorer() |
85 | | - .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); |
| 87 | + .AddApiExplorer(); |
86 | 88 |
|
87 | 89 | services |
88 | 90 | .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) |
163 | 165 | }); |
164 | 166 |
|
165 | 167 | 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 | + } |
166 | 174 | } |
167 | 175 | } |
168 | 176 | } |
0 commit comments