Skip to content

ModelsGenerator to IModelsGenerator in BuildModelsBuilderController#16919

Merged
kjac merged 2 commits intoumbraco:contribfrom
KXCPH:temp/16918
Sep 9, 2024
Merged

ModelsGenerator to IModelsGenerator in BuildModelsBuilderController#16919
kjac merged 2 commits intoumbraco:contribfrom
KXCPH:temp/16918

Conversation

@kasparboelkjeldsen
Copy link
Copy Markdown
Contributor

@kasparboelkjeldsen kasparboelkjeldsen commented Aug 15, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

This fixes #16918

Description

I have changed BuildModelsBuilderController to use IModelsGenerator so the functionality is the same as the SourceCodeAuto functionality.

It should have no impact on Umbraco out of the box, but allow easlier ModelsBuilder-replacement for developers.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 15, 2024

Hi there @kasparboelkjeldsen, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@emmagarland
Copy link
Copy Markdown
Collaborator

Hi @kasparboelkjeldsen

Thanks for your PR to fix #16918, to change ModelsGenerator to IModelsGenerator.

One of the Core Collaborators team will review this as soon as possible. 👍

Best wishes

Emma

@Matthew-Wise Matthew-Wise self-assigned this Aug 25, 2024
@kjac kjac self-requested a review September 2, 2024 07:49
@kjac
Copy link
Copy Markdown
Contributor

kjac commented Sep 3, 2024

Hi @kasparboelkjeldsen,

Sorry for the belated response on this one. And thanks for the PR 👍

Your fix works just fine, but we need it to be backwards compatible. This unfortunately entails adding a few more constructors with obsoletion.

I think it goes something like this:

    [ActivatorUtilitiesConstructor]
    public BuildModelsBuilderController(
        IOptionsMonitor<ModelsBuilderSettings> modelsBuilderSettings,
        ModelsGenerationError mbErrors,
        IModelsGenerator modelGenerator)
    {
        _mbErrors = mbErrors;
        _modelGenerator = modelGenerator;
        _modelsBuilderSettings = modelsBuilderSettings.CurrentValue;

        modelsBuilderSettings.OnChange(x => _modelsBuilderSettings = x);
    }

    [Obsolete("Please use the constructor that accepts IModelsGenerator only. Will be removed in V16.")]
    public BuildModelsBuilderController(
        IOptionsMonitor<ModelsBuilderSettings> modelsBuilderSettings,
        ModelsGenerationError mbErrors,
        ModelsGenerator modelGenerator)
        : this(modelsBuilderSettings, mbErrors, (IModelsGenerator)modelGenerator)
    {
    }

    // this constructor is required for the DI, otherwise it'll throw an "Ambiguous Constructor" errors at boot time.
    [Obsolete("Please use the constructor that accepts IModelsGenerator only. Will be removed in V16.")]
    public BuildModelsBuilderController(
        IOptionsMonitor<ModelsBuilderSettings> modelsBuilderSettings,
        ModelsGenerationError mbErrors,
        IModelsGenerator modelGenerator,
        ModelsGenerator notUsed)
        : this(modelsBuilderSettings, mbErrors, modelGenerator)
    {
    }
  • The first constructor is your newly introduced one. This will be preferred by the .NET framework because of the ActivatorUtilitiesConstructor annotation.
  • The second is the old constructor for backwards compat.
  • The third constructor is to make the DI happy. Having only the other two, the DI won't be able to choose a constructor because. This is the only workaround that can be isolated within this class.

@kasparboelkjeldsen
Copy link
Copy Markdown
Contributor Author

@kjac noted - I've updated the pull request with the 2 obsolete constructors and the Activator attribute, as well as verified it still is working as intended locally.

Copy link
Copy Markdown
Contributor

@kjac kjac left a comment

Choose a reason for hiding this comment

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

Good stuff, @kasparboelkjeldsen 💪

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BuildModelsBuilderController should use IModelsGenerator instead of ModelsGenerator

4 participants