Skip to content

Commit 77ea59c

Browse files
Require options and fix resolving of root path
1 parent bc0ac62 commit 77ea59c

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/ImageSharp.Web/Caching/PhysicalFileSystemCache.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ public PhysicalFileSystemCache(
4747
#endif
4848
FormatUtilities formatUtilities)
4949
{
50+
Guard.NotNull(options, nameof(options));
5051
Guard.NotNull(environment, nameof(environment));
51-
Guard.NotNullOrWhiteSpace(environment.WebRootPath, nameof(environment.WebRootPath));
52-
53-
// Allow configuration of the cache without having to register everything
54-
PhysicalFileSystemCacheOptions cacheOptions = options != null ? options.Value : new();
55-
this.cacheRootPath = GetCacheRoot(cacheOptions, environment.WebRootPath, environment.ContentRootPath);
56-
this.cacheFolderDepth = (int)cacheOptions.CacheFolderDepth;
5752

53+
this.cacheRootPath = GetCacheRoot(options.Value, environment.WebRootPath, environment.ContentRootPath);
54+
this.cacheFolderDepth = (int)options.Value.CacheFolderDepth;
5855
this.formatUtilities = formatUtilities;
5956
}
6057

@@ -67,9 +64,7 @@ public PhysicalFileSystemCache(
6764
/// <returns><see cref="string"/> representing the fully qualified cache root path.</returns>
6865
internal static string GetCacheRoot(PhysicalFileSystemCacheOptions cacheOptions, string webRootPath, string contentRootPath)
6966
{
70-
string cacheRoot = string.IsNullOrWhiteSpace(cacheOptions.CacheRootPath)
71-
? webRootPath
72-
: cacheOptions.CacheRootPath;
67+
string cacheRoot = cacheOptions.CacheRootPath ?? webRootPath ?? "wwwroot";
7368

7469
return Path.IsPathFullyQualified(cacheRoot)
7570
? Path.Combine(cacheRoot, cacheOptions.CacheFolder)

src/ImageSharp.Web/Providers/PhysicalFileSystemProvider.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ public PhysicalFileSystemProvider(
4242
#endif
4343
FormatUtilities formatUtilities)
4444
{
45+
Guard.NotNull(options, nameof(options));
4546
Guard.NotNull(environment, nameof(environment));
46-
Guard.NotNullOrWhiteSpace(environment.WebRootPath, nameof(environment.WebRootPath));
47-
48-
// Allow configuration of the provider without having to register everything
49-
PhysicalFileSystemProviderOptions providerOptions = options != null ? options.Value : new();
50-
this.providerRootPath = GetProviderRoot(providerOptions, environment.WebRootPath, environment.ContentRootPath);
5147

48+
this.providerRootPath = GetProviderRoot(options.Value, environment.WebRootPath, environment.ContentRootPath);
5249
this.formatUtilities = formatUtilities;
5350
}
5451

@@ -87,9 +84,7 @@ public Task<IImageResolver> GetAsync(HttpContext context)
8784
/// <returns><see cref="string"/> representing the fully qualified provider root path.</returns>
8885
internal static string GetProviderRoot(PhysicalFileSystemProviderOptions providerOptions, string webRootPath, string contentRootPath)
8986
{
90-
string providerRoot = string.IsNullOrWhiteSpace(providerOptions.ProviderRootPath)
91-
? webRootPath
92-
: providerOptions.ProviderRootPath;
87+
string providerRoot = providerOptions.ProviderRootPath ?? webRootPath ?? "wwwroot";
9388

9489
return Path.IsPathFullyQualified(providerRoot)
9590
? providerRoot

0 commit comments

Comments
 (0)