Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple EntityTypeConfigurationAttribute for entity types #34710

Open
foreverstupid opened this issue Sep 18, 2024 · 1 comment
Open

Comments

@foreverstupid
Copy link

EF Core provides a way to split and encapsulate entity configuration actions via IEntityTypeConfiguration<T> interface. Moreover, it allows creating multiple implementations and register all of them from OnModelCreating method.

However, in some cases it is more convenient to keep OnModelCreating method untouched (e.g. when you deal with source generation and have no access to the database context class, but only to the entity type). For that purpose EF Core provides the EntityTypeConfigurationAttribute. It marks an entity class slecifying the type of the mentioned above interface realization, that should be used for the entity configuring.

The main problem is that this attribute doesn't allow multiple declarations on the same type. So, you cannot specify several configuration classes for the entity type.

Scenario where such a feature is convenient
You have two source generators. Both of them generate some logic for configuration entities and have access to the entities assemblies. But none of them has access to an assembly where the database context is declared. Keep in mind, that generators are independent and cannot be synchronized. In that case you could make entities be partial and each generator could create additional partial declaration of the entity whith EntityTypeConfigurationAttribute pointing to the corresponding generated implementation of IEntityTypeConfiguration<T> interface.

The EntityTypeConfigurationAttribute should allow multiple declarations on the same entity type. EF Core should analyze all of them, ignore duplicates in specified configuration classes types, and then apply configurations in any order. Alternatively, the attribute can provide an integer order property to specify aplying order.

@AndriySvyryd
Copy link
Member

The order could be specified by #22035

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

No branches or pull requests

2 participants