Skip to content

Commit 7ffd390

Browse files
Add PostConfigure extension method
1 parent 5719a49 commit 7ffd390

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class ImageSharpBuilderExtensions
2222
/// <summary>
2323
/// Sets the given <see cref="IRequestParser"/> adding it to the service collection.
2424
/// </summary>
25-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IRequestParser"/>to add.</typeparam>
25+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IRequestParser"/> to add.</typeparam>
2626
/// <param name="builder">The core builder.</param>
2727
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
2828
public static IImageSharpBuilder SetRequestParser<TImplementation>(this IImageSharpBuilder builder)
@@ -49,7 +49,7 @@ public static IImageSharpBuilder SetRequestParser(this IImageSharpBuilder builde
4949
/// <summary>
5050
/// Sets the given <see cref="IImageCache"/> adding it to the service collection.
5151
/// </summary>
52-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageCache"/>to add.</typeparam>
52+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageCache"/> to add.</typeparam>
5353
/// <param name="builder">The core builder.</param>
5454
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
5555
public static IImageSharpBuilder SetCache<TImplementation>(this IImageSharpBuilder builder)
@@ -103,7 +103,7 @@ public static IImageSharpBuilder SetCacheKey(this IImageSharpBuilder builder, Fu
103103
/// <summary>
104104
/// Sets the given <see cref="ICacheHash"/> adding it to the service collection.
105105
/// </summary>
106-
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICacheHash"/>to add.</typeparam>
106+
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICacheHash"/> to add.</typeparam>
107107
/// <param name="builder">The core builder.</param>
108108
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
109109
public static IImageSharpBuilder SetCacheHash<TImplementation>(this IImageSharpBuilder builder)
@@ -130,7 +130,7 @@ public static IImageSharpBuilder SetCacheHash(this IImageSharpBuilder builder, F
130130
/// <summary>
131131
/// Adds the given <see cref="IImageProvider"/> to the provider collection within the service collection.
132132
/// </summary>
133-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/>to add.</typeparam>
133+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/> to add.</typeparam>
134134
/// <param name="builder">The core builder.</param>
135135
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
136136
public static IImageSharpBuilder AddProvider<TImplementation>(this IImageSharpBuilder builder)
@@ -144,7 +144,7 @@ public static IImageSharpBuilder AddProvider<TImplementation>(this IImageSharpBu
144144
/// <summary>
145145
/// Adds the given <see cref="IImageProvider"/> to the provider collection within the service collection.
146146
/// </summary>
147-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/>to add.</typeparam>
147+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/> to add.</typeparam>
148148
/// <param name="builder">The core builder.</param>
149149
/// <param name="implementationFactory">The factory method for returning a <see cref="IImageProvider"/>.</param>
150150
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
@@ -159,7 +159,7 @@ public static IImageSharpBuilder AddProvider<TImplementation>(this IImageSharpBu
159159
/// <summary>
160160
/// Inserts the given <see cref="IImageProvider"/> at the give index into to the provider collection within the service collection.
161161
/// </summary>
162-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/>to add.</typeparam>
162+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/> to add.</typeparam>
163163
/// <param name="builder">The core builder.</param>
164164
/// <param name="index">The zero-based index at which the provider should be inserted.</param>
165165
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
@@ -179,7 +179,7 @@ public static IImageSharpBuilder InsertProvider<TImplementation>(this IImageShar
179179
/// <summary>
180180
/// Inserts the given <see cref="IImageProvider"/> at the give index into the provider collection within the service collection.
181181
/// </summary>
182-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/>to add.</typeparam>
182+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/> to add.</typeparam>
183183
/// <param name="builder">The core builder.</param>
184184
/// <param name="index">The zero-based index at which the provider should be inserted.</param>
185185
/// <param name="implementationFactory">The factory method for returning a <see cref="IImageProvider"/>.</param>
@@ -200,7 +200,7 @@ public static IImageSharpBuilder InsertProvider<TImplementation>(this IImageShar
200200
/// <summary>
201201
/// Removes the given <see cref="IImageProvider"/> from the provider collection within the service collection.
202202
/// </summary>
203-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/>to add.</typeparam>
203+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageProvider"/> to add.</typeparam>
204204
/// <param name="builder">The core builder.</param>
205205
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
206206
public static IImageSharpBuilder RemoveProvider<TImplementation>(this IImageSharpBuilder builder)
@@ -230,7 +230,7 @@ public static IImageSharpBuilder ClearProviders(this IImageSharpBuilder builder)
230230
/// <summary>
231231
/// Adds the given <see cref="IImageWebProcessor"/> to the processor collection within the service collection.
232232
/// </summary>
233-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageWebProcessor"/>to add.</typeparam>
233+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageWebProcessor"/> to add.</typeparam>
234234
/// <param name="builder">The core builder.</param>
235235
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
236236
public static IImageSharpBuilder AddProcessor<TImplementation>(this IImageSharpBuilder builder)
@@ -244,7 +244,7 @@ public static IImageSharpBuilder AddProcessor<TImplementation>(this IImageSharpB
244244
/// <summary>
245245
/// Adds the given <see cref="IImageWebProcessor"/> to the processor collection within the service collection.
246246
/// </summary>
247-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageWebProcessor"/>to add.</typeparam>
247+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageWebProcessor"/> to add.</typeparam>
248248
/// <param name="builder">The core builder.</param>
249249
/// <param name="implementationFactory">The factory method for returning a <see cref="IImageProvider"/>.</param>
250250
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
@@ -259,7 +259,7 @@ public static IImageSharpBuilder AddProcessor<TImplementation>(this IImageSharpB
259259
/// <summary>
260260
/// Removes the given <see cref="IImageWebProcessor"/> from the processor collection within the service collection.
261261
/// </summary>
262-
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageWebProcessor"/>to add.</typeparam>
262+
/// <typeparam name="TImplementation">The type of class implementing <see cref="IImageWebProcessor"/> to add.</typeparam>
263263
/// <param name="builder">The core builder.</param>
264264
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
265265
public static IImageSharpBuilder RemoveProcessor<TImplementation>(this IImageSharpBuilder builder)
@@ -289,7 +289,7 @@ public static IImageSharpBuilder ClearProcessors(this IImageSharpBuilder builder
289289
/// <summary>
290290
/// Adds the given <see cref="ICommandConverter"/> to the converter collection within the service collection.
291291
/// </summary>
292-
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICommandConverter"/>to add.</typeparam>
292+
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICommandConverter"/> to add.</typeparam>
293293
/// <param name="builder">The core builder.</param>
294294
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
295295
public static IImageSharpBuilder AddConverter<TImplementation>(this IImageSharpBuilder builder)
@@ -303,7 +303,7 @@ public static IImageSharpBuilder AddConverter<TImplementation>(this IImageSharpB
303303
/// <summary>
304304
/// Adds the given <see cref="ICommandConverter"/> to the converter collection within the service collection.
305305
/// </summary>
306-
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICommandConverter"/>to add.</typeparam>
306+
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICommandConverter"/> to add.</typeparam>
307307
/// <param name="builder">The core builder.</param>
308308
/// <param name="implementationFactory">The factory method for returning a <see cref="ICommandConverter"/>.</param>
309309
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
@@ -318,7 +318,7 @@ public static IImageSharpBuilder AddConverter<TImplementation>(this IImageSharpB
318318
/// <summary>
319319
/// Removes the given <see cref="ICommandConverter"/> from the converter collection within the service collection.
320320
/// </summary>
321-
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICommandConverter"/>to add.</typeparam>
321+
/// <typeparam name="TImplementation">The type of class implementing <see cref="ICommandConverter"/> to add.</typeparam>
322322
/// <param name="builder">The core builder.</param>
323323
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
324324
public static IImageSharpBuilder RemoveConverter<TImplementation>(this IImageSharpBuilder builder)
@@ -350,12 +350,12 @@ public static IImageSharpBuilder ClearConverters(this IImageSharpBuilder builder
350350
/// </summary>
351351
/// <typeparam name="TOptions">The options type to be configured.</typeparam>
352352
/// <param name="builder">The core builder.</param>
353-
/// <param name="configuration">The configuration being bound.</param>
353+
/// <param name="config">The configuration being bound.</param>
354354
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
355-
public static IImageSharpBuilder Configure<TOptions>(this IImageSharpBuilder builder, IConfiguration configuration)
355+
public static IImageSharpBuilder Configure<TOptions>(this IImageSharpBuilder builder, IConfiguration config)
356356
where TOptions : class
357357
{
358-
builder.Services.Configure<TOptions>(configuration);
358+
builder.Services.Configure<TOptions>(config);
359359

360360
return builder;
361361
}
@@ -375,6 +375,21 @@ public static IImageSharpBuilder Configure<TOptions>(this IImageSharpBuilder bui
375375
return builder;
376376
}
377377

378+
/// <summary>
379+
/// Registers an action used to configure a particular type of options. Note: These are run after all <see cref="Configure{TOptions}(IImageSharpBuilder, Action{TOptions})"/>.
380+
/// </summary>
381+
/// <typeparam name="TOptions">The options type to be configured.</typeparam>
382+
/// <param name="builder">The core builder.</param>
383+
/// <param name="configureOptions">The action used to configure the options.</param>
384+
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
385+
public static IImageSharpBuilder PostConfigure<TOptions>(this IImageSharpBuilder builder, Action<TOptions> configureOptions)
386+
where TOptions : class
387+
{
388+
builder.Services.PostConfigure(configureOptions);
389+
390+
return builder;
391+
}
392+
378393
private static Type GetImplementationType(this ServiceDescriptor descriptor)
379394
=> descriptor.ImplementationType
380395
?? descriptor.ImplementationInstance?.GetType()

0 commit comments

Comments
 (0)