Skip to content

Commit 2a375e7

Browse files
Apply review comments/cleanup
1 parent f1b8e91 commit 2a375e7

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/ImageSharp.Web/DependencyInjection/ImageSharpBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using System;
54
using Microsoft.Extensions.DependencyInjection;
65

76
namespace SixLabors.ImageSharp.Web.DependencyInjection
@@ -15,7 +14,7 @@ internal class ImageSharpBuilder : IImageSharpBuilder
1514
/// Initializes a new instance of the <see cref="ImageSharpBuilder"/> class.
1615
/// </summary>
1716
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
18-
public ImageSharpBuilder(IServiceCollection services) => this.Services = services ?? throw new ArgumentNullException(nameof(services));
17+
public ImageSharpBuilder(IServiceCollection services) => this.Services = services;
1918

2019
/// <inheritdoc/>
2120
public IServiceCollection Services { get; }

src/ImageSharp.Web/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static class ServiceCollectionExtensions
2424
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
2525
/// <returns>An <see cref="IImageSharpBuilder"/> that can be used to further configure the ImageSharp services.</returns>
2626
public static IImageSharpBuilder AddImageSharp(this IServiceCollection services)
27-
=> new ImageSharpBuilder(services).AddRequiredServices().AddDefaultServices();
27+
=> new ImageSharpBuilder(services).AddDefaultServices();
2828

2929
/// <summary>
3030
/// Adds ImageSharp services to the specified <see cref="IServiceCollection" /> with the given options.
@@ -35,20 +35,15 @@ public static IImageSharpBuilder AddImageSharp(this IServiceCollection services)
3535
public static IImageSharpBuilder AddImageSharp(this IServiceCollection services, Action<ImageSharpMiddlewareOptions> configureOptions)
3636
=> services.AddImageSharp().Configure(configureOptions);
3737

38-
private static IImageSharpBuilder AddRequiredServices(this IImageSharpBuilder builder)
38+
private static IImageSharpBuilder AddDefaultServices(this IImageSharpBuilder builder)
3939
{
4040
builder.Services.AddSingleton<FormatUtilities>();
41-
builder.Services.AddSingleton<CommandParser>();
4241
builder.Services.AddSingleton<AsyncKeyReaderWriterLock<string>>();
4342

43+
// Command parsing
44+
builder.Services.AddSingleton<CommandParser>();
4445
builder.SetRequestParser<QueryCollectionRequestParser>();
4546

46-
builder.SetCache<PhysicalFileSystemCache>();
47-
48-
builder.SetCacheKey<UriRelativeLowerInvariantCacheKey>();
49-
50-
builder.SetCacheHash<SHA256CacheHash>();
51-
5247
builder.AddConverter<IntegralNumberConverter<sbyte>>();
5348
builder.AddConverter<IntegralNumberConverter<byte>>();
5449
builder.AddConverter<IntegralNumberConverter<short>>();
@@ -95,13 +90,15 @@ private static IImageSharpBuilder AddRequiredServices(this IImageSharpBuilder bu
9590
builder.AddConverter<ColorConverter>();
9691
builder.AddConverter<EnumConverter>();
9792

98-
return builder;
99-
}
93+
// Cache
94+
builder.SetCache<PhysicalFileSystemCache>();
95+
builder.SetCacheKey<UriRelativeLowerInvariantCacheKey>();
96+
builder.SetCacheHash<SHA256CacheHash>();
10097

101-
private static IImageSharpBuilder AddDefaultServices(this IImageSharpBuilder builder)
102-
{
98+
// Providers
10399
builder.AddProvider<PhysicalFileSystemProvider>();
104100

101+
// Processors
105102
builder.AddProcessor<ResizeWebProcessor>()
106103
.AddProcessor<FormatWebProcessor>()
107104
.AddProcessor<BackgroundColorWebProcessor>()

0 commit comments

Comments
 (0)