Skip to content

Commit 17d65a7

Browse files
Remove services.AddImageSharpCore
1 parent 1695866 commit 17d65a7

File tree

3 files changed

+31
-46
lines changed

3 files changed

+31
-46
lines changed

samples/ImageSharp.Web.Sample/Startup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Startup
3939
/// <param name="services">The collection of service desscriptors.</param>
4040
public void ConfigureServices(IServiceCollection services)
4141
{
42-
services.AddImageSharpCore()
42+
services.AddImageSharp()
4343
.SetRequestParser<QueryCollectionRequestParser>()
4444
.Configure<PhysicalFileSystemCacheOptions>(options =>
4545
{
@@ -102,7 +102,7 @@ private void ConfigureCustomServicesAndDefaultOptions(IServiceCollection service
102102

103103
private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services)
104104
{
105-
services.AddImageSharpCore(
105+
services.AddImageSharp(
106106
options =>
107107
{
108108
options.Configuration = Configuration.Default;
@@ -128,7 +128,9 @@ private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services
128128
provider.GetRequiredService<FormatUtilities>());
129129
})
130130
.SetCacheHash<CacheHash>()
131+
.ClearProviders()
131132
.AddProvider<PhysicalFileSystemProvider>()
133+
.ClearProcessors()
132134
.AddProcessor<ResizeWebProcessor>()
133135
.AddProcessor<FormatWebProcessor>()
134136
.AddProcessor<BackgroundColorWebProcessor>();

src/ImageSharp.Web/DependencyInjection/ImageSharpCoreBuilderExtensions.cs renamed to src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Linq;
76
using System.Reflection;
87
using Microsoft.Extensions.Configuration;
@@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp.Web.DependencyInjection
2120
/// <summary>
2221
/// Extension methods for <see cref="IImageSharpBuilder"/> that allow configuration of services.
2322
/// </summary>
24-
public static class ImageSharpCoreBuilderExtensions
23+
public static class ImageSharpBuilderExtensions
2524
{
2625
/// <summary>
2726
/// Sets the given <see cref="IRequestParser"/> adding it to the service collection.
@@ -243,6 +242,18 @@ public static IImageSharpBuilder RemoveProcessor<TProcessor>(this IImageSharpBui
243242
return builder;
244243
}
245244

245+
/// <summary>
246+
/// Removes all <see cref="IImageWebProcessor"/> instances from the processor collection within the service collection.
247+
/// </summary>
248+
/// <param name="builder">The core builder.</param>
249+
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
250+
public static IImageSharpBuilder ClearProcessors(this IImageSharpBuilder builder)
251+
{
252+
builder.Services.RemoveAll(typeof(IImageWebProcessor));
253+
254+
return builder;
255+
}
256+
246257
/// <summary>
247258
/// Registers an action used to configure a particular type of options.
248259
/// </summary>

src/ImageSharp.Web/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,67 +24,39 @@ 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-
{
28-
IImageSharpBuilder builder = AddImageSharpCore(services);
29-
30-
AddDefaultServices(builder);
31-
32-
return new ImageSharpBuilder(builder.Services);
33-
}
27+
=> AddImageSharp(services, _ => { });
3428

3529
/// <summary>
3630
/// Adds ImageSharp services to the specified <see cref="IServiceCollection" /> with the given options.
3731
/// </summary>
3832
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
3933
/// <param name="setupAction">An <see cref="Action{ImageSharpMiddlewareOptions}"/> to configure the provided <see cref="ImageSharpMiddlewareOptions"/>.</param>
4034
/// <returns>An <see cref="IImageSharpBuilder"/> that can be used to further configure the ImageSharp services.</returns>
41-
public static IImageSharpBuilder AddImageSharp(this IServiceCollection services, Action<ImageSharpMiddlewareOptions> setupAction)
42-
{
43-
IImageSharpBuilder builder = AddImageSharpCore(services, setupAction);
44-
45-
AddDefaultServices(builder);
46-
47-
return new ImageSharpBuilder(builder.Services);
48-
}
49-
50-
/// <summary>
51-
/// Provides the means to add essential ImageSharp services to the specified <see cref="IServiceCollection" /> with the given options.
52-
/// All additional services are required to be configured.
53-
/// </summary>
54-
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
55-
/// <param name="setupAction">An <see cref="Action{ImageSharpMiddlewareOptions}"/> to configure the provided <see cref="ImageSharpMiddlewareOptions"/>.</param>
56-
/// <returns>An <see cref="IImageSharpBuilder"/> that can be used to further configure the ImageSharp services.</returns>
57-
public static IImageSharpBuilder AddImageSharpCore(this IServiceCollection services, Action<ImageSharpMiddlewareOptions> setupAction)
35+
public static IImageSharpBuilder AddImageSharp(
36+
this IServiceCollection services,
37+
Action<ImageSharpMiddlewareOptions> setupAction)
5838
{
5939
Guard.NotNull(services, nameof(services));
40+
Guard.NotNull(setupAction, nameof(setupAction));
6041

6142
services.TryAddTransient<IConfigureOptions<ImageSharpMiddlewareOptions>, ImageSharpConfiguration>();
6243

6344
IImageSharpBuilder builder = new ImageSharpBuilder(services);
6445

65-
builder.Services.Configure(setupAction);
66-
67-
builder.SetMemoryAllocatorFromMiddlewareOptions();
68-
builder.SetFormatUtilitesFromMiddlewareOptions();
46+
AddDefaultServices(builder, setupAction);
6947

7048
return builder;
7149
}
7250

73-
/// <summary>
74-
/// Provides the means to add essential ImageSharp services to the specified <see cref="IServiceCollection" /> with the default options.
75-
/// All additional services are required to be configured.
76-
/// </summary>
77-
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
78-
/// <returns>An <see cref="IImageSharpBuilder"/> that can be used to further configure the ImageSharp services.</returns>
79-
public static IImageSharpBuilder AddImageSharpCore(this IServiceCollection services)
80-
=> AddImageSharpCore(services, _ => { });
81-
82-
/// <summary>
83-
/// Adds the default service to the service collection.
84-
/// </summary>
85-
/// <param name="builder">The <see cref="IImageSharpBuilder"/> that can be used to further configure the ImageSharp services.</param>
86-
private static void AddDefaultServices(IImageSharpBuilder builder)
51+
private static void AddDefaultServices(
52+
IImageSharpBuilder builder,
53+
Action<ImageSharpMiddlewareOptions> setupAction)
8754
{
55+
builder.Services.Configure(setupAction);
56+
57+
builder.SetMemoryAllocatorFromMiddlewareOptions();
58+
builder.SetFormatUtilitesFromMiddlewareOptions();
59+
8860
builder.SetRequestParser<QueryCollectionRequestParser>();
8961

9062
builder.SetCache<PhysicalFileSystemCache>();

0 commit comments

Comments
 (0)