Skip to content

Allow multiple IModelCustomizer #9330

Closed as not planned
Closed as not planned

Description

@AndriySvyryd

This would allow users to add an IModelCustomizer without having to override the provider one

Activity

  1. self-assigned this
    on Aug 3, 2017
  2. modified the milestone: 2.1.0 on Aug 4, 2017
  3. divega commented on Aug 4, 2017

    @divega
    Contributor

    @AndriySvyryd do you think we need to do this in 2.1 or is ok to have it in the backlog?

  4. added this to the Backlog milestone on Aug 4, 2017
  5. AndriySvyryd commented on Aug 4, 2017

    @AndriySvyryd
    MemberAuthor

    @divega Backlog is fine

  6. modified the milestones: 2.1.0, Backlog on Aug 23, 2017
  7. ajcvickers commented on Aug 23, 2017

    @ajcvickers
    Contributor

    Moving this to 2.1 based on feedback in #9225.

  8. added 3 commits that reference this issue on Sep 6, 2017
    d5977ae
    ac5135b
    1519acb
  9. AndriySvyryd commented on Sep 7, 2017

    @AndriySvyryd
    MemberAuthor

    This will be covered by #626

  10. removed their assignment
    on Sep 7, 2017
  11. removed this from the 2.1.0 milestone on Sep 7, 2017
  12. lauxjpn commented on Sep 6, 2020

    @lauxjpn
    Contributor

    This will be covered by #626

    Is that really the case? What is the intended procedure for providers to implement their own model customization without disturbing other extensions or custom user code that implements IModelCustomizer (especially in later releases like now)?

    We currently implemented JSON support in Pomelo for both, System.Text.Json and Newtonsoft.Json, based on the work done by @roji for Npgsql. The support is implemented in individual packages (one for each supported JSON library) and based on the underlying plugin infrastructure (like for the NTS implementation).

    Newtonsoft.Json uses a couple of DOM classes with properties that would normally be discovered as navigation properties by EF Core. We don't want that, because those classes and properties are being explicitly handled and translated by the query pipeline. It seems that the intended way to solve this problem is to implement IModelCustomizer and ignore the types.

    Doing so at this point in time could however break other extensions that users might already be using and existing user code that depends on their own IModelCustomizer implementation.

    We would also need different IModelCustomizer implementations, a MySqlJsonMicrosoftModelCustomizer and a MySqlJsonNewtonsoftModelCustomizer, of which one would be registered with DI for IModelCustomizer, depending on the JSON library actual used.

    That means that users and extension would potentially not only need to override just one provider specific implementation in our case, but both if they would want to support both JSON libraries, if they want to use their own IModelCustomizer as well.


    There seem to be some solutions to this issue for us:

    • Just override IModelSource instead (which should much more unlikely be already implemented by extensions or user code), let the provider specific model customizers implement a provider specific interface like IMySqlModelCustomizer that allows for multiple registrations, and then explicitly call all those provider specific model customizers in IModelSource.GetModel() in addition to the official IModelCustomizer implementation.

    • Allow multiple registrations for IModelCustomizer itself.


    Shouldn't IModelCustomizer allow multiple registrations in the first place?

  13. AndriySvyryd commented on Sep 6, 2020

    @AndriySvyryd
    MemberAuthor

    @lauxjpn You can do it in an IModelInitiliazed convention. IModelCustomizer should only be implemented if you need access to the context instance when creating the model.

  14. lauxjpn commented on Sep 6, 2020

    @lauxjpn
    Contributor

    @AndriySvyryd Thanks, I totally missed that option! This works much better than the first approach I outlined, because then we also would have wanted to use our own MySqlTestModelSource class when testing, which is simple to do for individual test fixtures, but hard to do an a global level for all test fixtures, because of its tight coupling to FixtureBase.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions