-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Specific Case
The sample to request design time services throws an InvalidOperationException (when executed with .NET 6 / ef7):
Unhandled exception. System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Design.IAnnotationCodeGenerator' while attempting to activate 'Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsCodeGeneratorDependencies'.
General Case
The sample to request design time services does not work for all listed services in section List of services.
According my tests the sample works only for a subset of services:
- .NET 5:
IAnnotationCodeGenerator,ICSharpHelper,IPluralizer,IMigrationsCodeGenerator,IMigrationsScaffolder - .NET 6-7:
IPluralizerandIScaffoldingModelFactory - .NET 8:
IModelCodeGenerator,IPluralizer,IScaffoldingModelFactory
Other services will return null or throw an exception due to unresolved dependencies.
Comparing the example with DesignTimeServicesBuilder.Build I assume that this is expected behaviour since the provider design-time services are not loaded.
Long story short
The section Using services should mention which services can be used effectively or the public API should get the capabilities to load provider, referenced and implementation design-time services equal to DesignTimeServicesBuilder.Build.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 2886eabf-4b28-c390-9634-14e623e8ec8e
- Version Independent ID: 1ef0f90d-664c-81f7-ee5d-f67dafce4ed1
- Content: Design-time services - EF Core
- Content Source: entity-framework/core/cli/services.md
- Product: entity-framework
- Technology: entity-framework-core
- GitHub Login: @bricelam
- Microsoft Alias: avickers