Skip to content

Commit 4444392

Browse files
author
Сергей Трегуб
committed
Stop using preprocessor directives
1 parent 9b01208 commit 4444392

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

ProjectTemplates/ReferenceProject/Startup.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929
* Getting started guide: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki/Getting-Started-Guide
3030
* More information about configuring project: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki
3131
*/
32-
3332
namespace ReferenceProject
3433
{
3534
public class Startup
3635
{
36+
IConfiguration Configuration { get; }
37+
IHostEnvironment HostEnvironment { get; }
38+
3739
public Startup(IConfiguration configuration, IHostEnvironment env)
3840
{
39-
Startup.Configuration = configuration;
41+
Configuration = configuration;
42+
HostEnvironment = env;
4043

4144
// See: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#content-formatting
4245
JsonConvert.DefaultSettings = () =>
@@ -47,19 +50,13 @@ public Startup(IConfiguration configuration, IHostEnvironment env)
4750
NullValueHandling = NullValueHandling.Ignore,
4851
DefaultValueHandling = DefaultValueHandling.Include,
4952
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
50-
#if DEBUG
51-
Formatting = Formatting.Indented
52-
#else
53-
Formatting = Formatting.None
54-
#endif
53+
Formatting = env.IsDevelopment() ? Formatting.Indented : Formatting.None
5554
};
5655
settings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
5756
return settings;
5857
};
5958
}
6059

61-
public static IConfiguration Configuration { get; private set; }
62-
6360
// This method gets called by the runtime. Use this method to add services to the container.
6461
public void ConfigureServices(IServiceCollection services)
6562
{
@@ -82,11 +79,7 @@ public void ConfigureServices(IServiceCollection services)
8279
options.JsonSerializerOptions.IgnoreNullValues = true;
8380
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
8481
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
85-
#if DEBUG
86-
options.JsonSerializerOptions.WriteIndented = true;
87-
#else
88-
options.JsonSerializerOptions.WriteIndented = false;
89-
#endif
82+
options.JsonSerializerOptions.WriteIndented = HostEnvironment.IsDevelopment();
9083
})
9184
.AddApiExplorer()
9285
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

0 commit comments

Comments
 (0)