Skip to content

docs: Document that ApplyConfigurationsFromAssembly requires a parameterless constructor#5366

Open
Aykuttonpc wants to merge 1 commit into
dotnet:mainfrom
Aykuttonpc:docs/3207-applyconfigs-parameterless-ctor
Open

docs: Document that ApplyConfigurationsFromAssembly requires a parameterless constructor#5366
Aykuttonpc wants to merge 1 commit into
dotnet:mainfrom
Aykuttonpc:docs/3207-applyconfigs-parameterless-ctor

Conversation

@Aykuttonpc
Copy link
Copy Markdown

Summary

Fixes #3207.

ApplyConfigurationsFromAssembly only instantiates configuration types that have a parameterless constructor, but this isn't currently documented. Users hit surprising behavior when their IEntityTypeConfiguration<T> implementations have non-default constructors (e.g. for DI).

This PR adds a [!NOTE] block to entity-framework/core/modeling/index.md next to the existing "order is undefined" note, describing:

  • A parameterless constructor is required — may be public or non-public (implementation: BindingFlags.Public | BindingFlags.NonPublic + Activator.CreateInstance(type, nonPublic: true) in ModelBuilder.cs).
  • Types lacking such a constructor are skipped, with a SkippedEntityTypeConfigurationWarning logged.
  • To apply a configuration whose constructor requires arguments, instantiate it manually and pass it to ApplyConfiguration.

Mirrors the style of the adjacent NOTE.

…sFromAssembly

- Add a NOTE block in entity-framework/core/modeling/index.md describing the parameterless constructor requirement.
- Clarify that the constructor may be public or non-public.
- Mention that types without one are skipped and a SkippedEntityTypeConfigurationWarning is logged.
- Point readers to ModelBuilder.ApplyConfiguration as the manual alternative.

Fixes dotnet#3207
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.

Document that IEntityTypeConfiguration.Configure() is not fired for entities without default constructor

1 participant