From 0422a5c063edf08939c3b095db86b09d62e8ea1c Mon Sep 17 00:00:00 2001 From: Abdulrahman Elnory <135131957+abdulrahmanelnory1@users.noreply.github.com> Date: Fri, 5 Dec 2025 22:06:33 +0200 Subject: [PATCH] fix: use IHostEnvironment for environment detection in PlayerService --- .../Services/PlayerService.cs | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Services/PlayerService.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Services/PlayerService.cs index bd3ed54..6907088 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Services/PlayerService.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Services/PlayerService.cs @@ -1,15 +1,15 @@ -using AutoMapper; +using AutoMapper; using Dotnet.Samples.AspNetCore.WebApi.Models; using Dotnet.Samples.AspNetCore.WebApi.Repositories; using Microsoft.Extensions.Caching.Memory; - namespace Dotnet.Samples.AspNetCore.WebApi.Services; public class PlayerService( IPlayerRepository playerRepository, ILogger logger, IMemoryCache memoryCache, - IMapper mapper + IMapper mapper, + IHostEnvironment hostEnvironment ) : IPlayerService { /// @@ -27,20 +27,6 @@ IMapper mapper /// private static readonly string CacheKey_RetrieveAsync = nameof(RetrieveAsync); - /// - /// The key used to store the environment variable for ASP.NET Core. - ///
- /// - /// Use multiple environments in ASP.NET Core - /// - ///
- private static readonly string AspNetCore_Environment = "ASPNETCORE_ENVIRONMENT"; - - /// - /// The value used to check if the environment is Development. - /// - private static readonly string Development = "Development"; - /* ------------------------------------------------------------------------- * Create * ---------------------------------------------------------------------- */ @@ -68,7 +54,7 @@ public async Task> RetrieveAsync() } else { - if (Environment.GetEnvironmentVariable(AspNetCore_Environment) == Development) + if (hostEnvironment.IsDevelopment()) { await SimulateRepositoryDelayAsync(); }