File tree Expand file tree Collapse file tree 4 files changed +11
-21
lines changed
tests/ImageSharp.Web.Tests/Helpers Expand file tree Collapse file tree 4 files changed +11
-21
lines changed Original file line number Diff line number Diff line change @@ -281,21 +281,5 @@ public static IImageSharpBuilder Configure<TOptions>(this IImageSharpBuilder bui
281281 builder . Services . Configure ( configureOptions ) ;
282282 return builder ;
283283 }
284-
285- /// <summary>
286- /// Sets the <see cref="FormatUtilities"/> configured by <see cref="ImageSharpMiddlewareOptions.Configuration"/>.
287- /// </summary>
288- /// <param name="builder">The core builder.</param>
289- /// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
290- internal static IImageSharpBuilder SetFormatUtilitesFromMiddlewareOptions ( this IImageSharpBuilder builder )
291- {
292- static FormatUtilities FormatUtilitiesFactory ( IServiceProvider s )
293- {
294- return new FormatUtilities ( s . GetRequiredService < IOptions < ImageSharpMiddlewareOptions > > ( ) . Value . Configuration ) ;
295- }
296-
297- builder . Services . AddSingleton ( FormatUtilitiesFactory ) ;
298- return builder ;
299- }
300284 }
301285}
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ private static void AddDefaultServices(
5454 {
5555 builder . Services . Configure ( setupAction ) ;
5656
57- builder . SetFormatUtilitesFromMiddlewareOptions ( ) ;
57+ builder . Services . AddSingleton < FormatUtilities > ( ) ;
5858
5959 builder . SetRequestParser < QueryCollectionRequestParser > ( ) ;
6060
Original file line number Diff line number Diff line change 55using System . Collections . Generic ;
66using System . Linq ;
77using Microsoft . AspNetCore . WebUtilities ;
8+ using Microsoft . Extensions . Options ;
89using Microsoft . Extensions . Primitives ;
910using SixLabors . ImageSharp . Formats ;
11+ using SixLabors . ImageSharp . Web . Middleware ;
1012using SixLabors . ImageSharp . Web . Processors ;
1113
1214namespace SixLabors . ImageSharp . Web
@@ -23,12 +25,14 @@ public sealed class FormatUtilities
2325 /// <summary>
2426 /// Initializes a new instance of the <see cref="FormatUtilities"/> class.
2527 /// </summary>
26- /// <param name="configuration ">The configuration .</param>
27- public FormatUtilities ( Configuration configuration )
28+ /// <param name="options ">The middleware options .</param>
29+ public FormatUtilities ( IOptions < ImageSharpMiddlewareOptions > options )
2830 {
31+ Guard . NotNull ( options , nameof ( options ) ) ;
32+
2933 // The formats contained in the configuration are used a lot in hash generation
3034 // so we need them to be enumerated to remove allocations and allow indexing.
31- this . imageFormats = configuration . ImageFormats . ToArray ( ) ;
35+ this . imageFormats = options . Value . Configuration . ImageFormats . ToArray ( ) ;
3236 for ( int i = 0 ; i < this . imageFormats . Length ; i ++ )
3337 {
3438 string [ ] extensions = this . imageFormats [ i ] . FileExtensions . ToArray ( ) ;
Original file line number Diff line number Diff line change 33
44using System . Collections . Generic ;
55using System . Linq ;
6+ using Microsoft . Extensions . Options ;
7+ using SixLabors . ImageSharp . Web . Middleware ;
68using Xunit ;
79
810namespace SixLabors . ImageSharp . Web . Tests . Helpers
@@ -12,7 +14,7 @@ public class FormatUtilitiesTests
1214 public static IEnumerable < object [ ] > DefaultExtensions =
1315 Configuration . Default . ImageFormats . SelectMany ( f => f . FileExtensions . Select ( e => new object [ ] { e , e } ) ) ;
1416
15- private static readonly FormatUtilities FormatUtilities = new FormatUtilities ( Configuration . Default ) ;
17+ private static readonly FormatUtilities FormatUtilities = new FormatUtilities ( Options . Create ( new ImageSharpMiddlewareOptions ( ) ) ) ;
1618
1719 [ Theory ]
1820 [ MemberData ( nameof ( DefaultExtensions ) ) ]
You can’t perform that action at this time.
0 commit comments