Repository navigation
Add extension method for easier ResourceManagementOptions registration (Lombiq Technologies: OCORE-208) - #17095
Conversation
| /// <typeparam name="T"> | ||
| /// The type of the service implementing <see cref="IConfigureOptions{ResourceManagementOptions}"/> to. | ||
| /// </typeparam> | ||
| public static IServiceCollection AddResourceManagementOptionsConfiguration<T>(this IServiceCollection services) |
There was a problem hiding this comment.
| public static IServiceCollection AddResourceManagementOptionsConfiguration<T>(this IServiceCollection services) | |
| public static IServiceCollection ConfigureResourceManagementOptions<T>(this IServiceCollection services) |
There was a problem hiding this comment.
Just one suggestion for these is enough for me to get the idea ;). However, I disagree: all of these shortcuts we have are named Add*, and for a reason: we're adding a type to the service collection, following methods like AddTransient. The Configure* methods deal directly with options classes, e.g.:
services.Configure<TemplateOptions>(o =>
{
o.MemberAccessStrategy.Register<DisplayMediaFieldViewModel>();
o.MemberAccessStrategy.Register<Anchor>();
o.Filters.AddFilter("img_tag", MediaFilters.ImgTag);
})This rather adds a service that implements IConfigureOptions<T>, only which in turn deals with options classes.
There was a problem hiding this comment.
Internally you configure ResourceManifest by adding an entry on each call
There was a problem hiding this comment.
Yeah, but that's not what this method is doing. If we were to swap the method in this:
services.Configure<ResourceManagementOptions>(o =>
{
_manifest = new ResourceManifest();
_manifest
.DefineScript("coming-soon")
.SetUrl("~/TheComingSoonTheme/js/scripts.min.js", "TheComingSoonTheme/js/scripts.js")
.SetVersion("6.0.5");
_manifest
.DefineStyle("coming-soon")
.SetUrl("~/TheComingSoonTheme/css/styles.min.css", "TheComingSoonTheme/css/styles.css")
.SetVersion("6.0.5");
o.ResourceManifests.Add(_manifest);
})Then we could name it ConfigureResourceManagementOptions and thus do:
services.ConfigureResourceManagementOptions(o =>
{
...
o.ResourceManifests.Add(_manifest);
})There the name would be appropriate. However, not for the AddTransient<IConfigureOptions<ResourceManagementOptions>, T>() substitution I implemented.
|
How about calling it AddResourceConfigurations? |
|
Even better, renamed. |
|
@hishamco anything else you'd like to add? |
|
Just minor changes and ready to merge |
|
Thanks! |
Following the pattern of all the
Add*extensions.The implementation is in
src/OrchardCore/OrchardCore.ResourceManagement/ServiceCollectionExtensions.cs, and the release notes are the notable changes, the rest is just search and replace.