Skip to content

Commit 259a2b6

Browse files
committed
Refactor SustainabilityService dependencies and syntax
Removed the `IWebHostEnvironment` dependency from the `SustainabilityService` class to simplify its design and reduce unnecessary dependencies. Updated array initialization syntax to use modern C# shorthand (`[...]`) for `ImageExtensions` and `FontExtensions`. Replaced default list initialization for `ResourceGroups` with a more concise empty list syntax (`[]`). Removed the unused `using Microsoft.AspNetCore.Hosting;` directive.
1 parent c2644b8 commit 259a2b6

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/Services/SustainabilityService.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CMS.Core;
22
using CMS.DataEngine;
3-
using Microsoft.AspNetCore.Hosting;
43
using Microsoft.Extensions.Logging;
54
using Microsoft.Extensions.Options;
65
using Microsoft.Playwright;
@@ -19,7 +18,6 @@ public interface ISustainabilityService
1918

2019
public class SustainabilityService : ISustainabilityService
2120
{
22-
private readonly IWebHostEnvironment _env;
2321
private readonly IEventLogService _eventLogService;
2422
private readonly IInfoProvider<SustainabilityPageDataInfo> _sustainabilityPageDataInfoProvider;
2523
private readonly IContentHubLinkService _contentHubLinkService;
@@ -28,8 +26,8 @@ public class SustainabilityService : ISustainabilityService
2826
private static readonly string ScriptPath = GetScriptPath();
2927
private const string SustainabilityDataTestId = "sustainabilityData";
3028

31-
private static readonly string[] ImageExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg", ".bmp", ".ico", ".avif" };
32-
private static readonly string[] FontExtensions = { ".woff", ".woff2", ".ttf", ".otf", ".eot" };
29+
private static readonly string[] ImageExtensions = [".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg", ".bmp", ".ico", ".avif"];
30+
private static readonly string[] FontExtensions = [".woff", ".woff2", ".ttf", ".otf", ".eot"];
3331

3432
private static string GetScriptPath()
3533
{
@@ -38,13 +36,11 @@ private static string GetScriptPath()
3836
}
3937

4038
public SustainabilityService(
41-
IWebHostEnvironment env,
4239
IEventLogService eventLogService,
4340
IInfoProvider<SustainabilityPageDataInfo> sustainabilityPageDataInfoProvider,
4441
IContentHubLinkService contentHubLinkService,
4542
IOptions<SustainabilityOptions> options)
4643
{
47-
_env = env;
4844
_eventLogService = eventLogService;
4945
_sustainabilityPageDataInfoProvider = sustainabilityPageDataInfoProvider;
5046
_contentHubLinkService = contentHubLinkService;
@@ -187,7 +183,7 @@ await page.EvaluateAsync($@"() => {{
187183
TotalEmissions = sustainabilityPageDataInfo.TotalEmissions,
188184
CarbonRating = sustainabilityPageDataInfo.CarbonRating,
189185
GreenHostingStatus = sustainabilityPageDataInfo.GreenHostingStatus,
190-
ResourceGroups = resourceGroups ?? new List<ExternalResourceGroup>(),
186+
ResourceGroups = resourceGroups ?? [],
191187
};
192188
}
193189

0 commit comments

Comments
 (0)