Skip to content

Allow to specify dependencies in IEntityTypeConfiguration #22035

Description

@AndriySvyryd
    IEnumerable<IEntityTypeConfiguration> Predecessors {get;}

This will allow ApplyConfigurationsFromAssembly to apply them in correct order, see #21304

Also add a bool parameter to ApplyConfigurationsFromAssembly that, when set to true, will make the closest base class configuration a predecessor by default and if the opposite is specified explicitly then it will override the default.

Activity

  1. added this to the Backlog milestone on Aug 14, 2020
  2. self-assigned this
    on Sep 30, 2020
  3. benlongo commented on Aug 4, 2022

    @benlongo

    It's really nice to have IEntityConfiguration co-located with the entity in question so you don't have to hunt for it, but once I started dealing with some shadow properties I ran into this.

  4. added
    good first issue
    on Oct 19, 2022
  5. sjb-sjb commented on Sep 18, 2023

    @sjb-sjb

    Might make sense to have the inverse attribute from the one proposed, It would be an attribute that can be put on a base class saying in effect that derived classes all depend on the base class. That way the design decision can be made by the base class rather than by an unknown number of derived classes.

  6. AndriySvyryd commented on Sep 21, 2023

    @AndriySvyryd
    MemberAuthor

    @sjb-sjb If the derived classes are unknown then how would they be specified as successors in the base class configuration?
    Generally, there are fewer predecessors than successors and they are more practical to specify.

    That said, if a compelling use case is presented, we could add both ways of specifying dependencies.

  7. sjb-sjb commented on Sep 21, 2023

    @sjb-sjb

    Hi @AndriySvyryd the descendants would not be specified, the ordering relation would apply to all derived entity classes’ configurations in the assembly. In other words we would only specify DescendantsAreSuccessors = true in the base class’s IEntityTypeConfiguration. The value is you do not have to list the derived classes explicitly or know what they are in advance. It’s logical since typically the design of the base class should not require knowing what the derived classes are.

    Ideally there would be a way to get this to work across assemblies based on the dependencies specified in the build.

    I said “attribute” in my comment above but I see we are actually talking about interface properties.

  8. AndriySvyryd commented on Sep 21, 2023

    @AndriySvyryd
    MemberAuthor

    @sjb-sjb This is a more general feature that would allow specifying arbitrary ordering constraints, not just base/derived, but the user would need to specify the dependency explicitly and statically. Wouldn't this be enough for your scenario?

  9. sjb-sjb commented on Sep 21, 2023

    @sjb-sjb

    Note I agree with the proposed feature, I’m suggesting adding an additional element.

    I think it logically makes sense for the base class to state a requirement that it be configured first, rather than making this optimal for the descendants. There are likely reasons from the base class’s point of view why it needs to be configured first and therefore it makes sense for the base class to be able to configure itself first without allowing the descendants to break the ordering. Otherwise the situation is a bit analogous to having the derived classes decide whether or not to call the base constructor first.

  10. sjb-sjb commented on Sep 21, 2023

    @sjb-sjb

    Indeed arguably another approach would be to simply say that if Configure is defined for a class then it will be executed before Configure of derived classes. Since you have to analyze the relationships anyway and sort them, I don’t think there is much efficiency gain by omitting this feature. I don’t think that derived classes should be able to force their configuration to go ahead of base configuration.

  11. AndriySvyryd commented on Sep 21, 2023

    @AndriySvyryd
    MemberAuthor

    Sure, we can make the closest base class configuration a predecessor by default and if the opposite is specified explicitly then it will override the default.

  12. sjb-sjb commented on Sep 22, 2023

    @sjb-sjb

    By “closest base class” do you mean the closest base class that has an EntityTypeConfiguration attribute? I guess if there is no attribute then there is no Configure function to call. Is there a war to do this with Fluent as well?

  13. AndriySvyryd commented on Sep 22, 2023

    @AndriySvyryd
    MemberAuthor

    By “closest base class” do you mean the closest base class that has an EntityTypeConfiguration attribute? I guess if there is no attribute then there is no Configure function to call.

    Yes

    Is there a war to do this with Fluent as well?

    Not sure what you mean, EntityTypeConfiguration classes use Fluent API.

  14. sjb-sjb commented on Sep 28, 2023

    @sjb-sjb
  15. removed
    good first issue
    on May 14, 2024
  16. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions