efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Add a service to configure conventions

Open AndriySvyryd opened this issue 9 months ago • 2 comments

It will be similar to IModelCustomizer:

public interface IConventionCustomizer
{
    /// <summary>
    ///     Sets model defaults and configures conventions before they run for a given context.
    /// </summary>
    /// <remarks>
    ///     If any instance data from <paramref name="context" /> is
    ///     used when building the model, then the implementation of <see cref="IModelCacheKeyFactory.Create(DbContext, bool)" />
    ///     also needs to be updated to ensure the model is cached correctly.
    /// </remarks>
    /// <param name="configurationBuilder">
    ///     The builder being used to set defaults and configure conventions that will be used to build the model for this context.
    /// </param>
    /// <param name="context">
    ///     The context instance that the model is being created for.
    /// </param>
    void Customize(ModelConfigurationBuilder configurationBuilder, DbContext context);
}

The default implementation will call context.ConfigureConventions(configurationBuilder);

AndriySvyryd avatar Apr 07 '25 18:04 AndriySvyryd

Is it different from IConventionSetPlugin ?

PhenX avatar Apr 10 '25 19:04 PhenX

It's not a plugin service, so it can be replaced using ReplaceService. Also, it gets a ModelConfigurationBuilder, so it can be used to apply other pre-convention configuration.

AndriySvyryd avatar Apr 11 '25 00:04 AndriySvyryd