Skip to content

Add extension method for easier ResourceManagementOptions registration (Lombiq Technologies: OCORE-208) - #17095

Merged
Piedone merged 9 commits into
OrchardCMS:mainfrom
Lombiq:issue/OCORE-208
Nov 29, 2024
Merged

Piedone merged 9 commits into
OrchardCMS:mainfrom
Lombiq:issue/OCORE-208

Conversation

@Piedone

@Piedone Piedone commented Nov 28, 2024 •

Copy link
Copy Markdown
Member

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.

@Piedone
Piedone requested a review from MikeAlhayek November 28, 2024 23:32
Comment thread src/OrchardCore/OrchardCore.ResourceManagement/ServiceCollectionExtensions.cs Outdated
/// <typeparam name="T">
/// The type of the service implementing <see cref="IConfigureOptions{ResourceManagementOptions}"/> to.
/// </typeparam>
public static IServiceCollection AddResourceManagementOptionsConfiguration<T>(this IServiceCollection services)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static IServiceCollection AddResourceManagementOptionsConfiguration<T>(this IServiceCollection services)
public static IServiceCollection ConfigureResourceManagementOptions<T>(this IServiceCollection services)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally you configure ResourceManifest by adding an entry on each call

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/OrchardCore.Modules/OrchardCore.ContentFields/Startup.cs Outdated
Comment thread src/OrchardCore.Modules/OrchardCore.ContentPreview/Startup.cs Outdated
Comment thread src/OrchardCore.Modules/OrchardCore.ContentTypes/Startup.cs Outdated
Comment thread src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs Outdated
Comment thread src/OrchardCore.Themes/TheBlogTheme/Startup.cs Outdated
Comment thread src/OrchardCore.Themes/TheComingSoonTheme/Startup.cs Outdated
Comment thread src/docs/reference/modules/Resources/README.md Outdated
Comment thread src/docs/releases/3.0.0.md Outdated
Comment thread src/docs/releases/3.0.0.md Outdated
@MikeAlhayek

Copy link
Copy Markdown
Member

How about calling it AddResourceConfigurations?

@Piedone

Piedone commented Nov 29, 2024

Copy link
Copy Markdown
Member Author

Even better, renamed.

@MikeAlhayek MikeAlhayek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions

Comment thread src/docs/releases/3.0.0.md Outdated
Comment thread src/docs/releases/3.0.0.md
Comment thread src/docs/reference/modules/Resources/README.md Outdated
Comment thread src/OrchardCore/OrchardCore.ResourceManagement/ServiceCollectionExtensions.cs Outdated
Piedone and others added 3 commits November 29, 2024 02:25
Co-authored-by: Mike Alhayek <mike@crestapps.com>
Co-authored-by: Mike Alhayek <mike@crestapps.com>
@Piedone

Piedone commented Nov 29, 2024

Copy link
Copy Markdown
Member Author

@hishamco anything else you'd like to add?

Comment thread src/docs/releases/3.0.0.md Outdated
Comment thread src/docs/releases/3.0.0.md Outdated
@hishamco

Copy link
Copy Markdown
Member

Just minor changes and ready to merge

Piedone and others added 2 commits November 29, 2024 02:33
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
@Piedone

Piedone commented Nov 29, 2024

Copy link
Copy Markdown
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants