Skip to content

Commit 0422a5c

Browse files
fix: use IHostEnvironment for environment detection in PlayerService
1 parent 48ddb14 commit 0422a5c

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

src/Dotnet.Samples.AspNetCore.WebApi/Services/PlayerService.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using AutoMapper;
1+
using AutoMapper;
22
using Dotnet.Samples.AspNetCore.WebApi.Models;
33
using Dotnet.Samples.AspNetCore.WebApi.Repositories;
44
using Microsoft.Extensions.Caching.Memory;
5-
65
namespace Dotnet.Samples.AspNetCore.WebApi.Services;
76

87
public class PlayerService(
98
IPlayerRepository playerRepository,
109
ILogger<PlayerService> logger,
1110
IMemoryCache memoryCache,
12-
IMapper mapper
11+
IMapper mapper,
12+
IHostEnvironment hostEnvironment
1313
) : IPlayerService
1414
{
1515
/// <summary>
@@ -27,20 +27,6 @@ IMapper mapper
2727
/// </summary>
2828
private static readonly string CacheKey_RetrieveAsync = nameof(RetrieveAsync);
2929

30-
/// <summary>
31-
/// The key used to store the environment variable for ASP.NET Core.
32-
/// <br/>
33-
/// <see href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-8.0">
34-
/// Use multiple environments in ASP.NET Core
35-
/// </see>
36-
/// </summary>
37-
private static readonly string AspNetCore_Environment = "ASPNETCORE_ENVIRONMENT";
38-
39-
/// <summary>
40-
/// The value used to check if the environment is Development.
41-
/// </summary>
42-
private static readonly string Development = "Development";
43-
4430
/* -------------------------------------------------------------------------
4531
* Create
4632
* ---------------------------------------------------------------------- */
@@ -68,7 +54,7 @@ public async Task<List<PlayerResponseModel>> RetrieveAsync()
6854
}
6955
else
7056
{
71-
if (Environment.GetEnvironmentVariable(AspNetCore_Environment) == Development)
57+
if (hostEnvironment.IsDevelopment())
7258
{
7359
await SimulateRepositoryDelayAsync();
7460
}

0 commit comments

Comments
 (0)