diff --git a/src/EFCore.Relational/Infrastructure/EntityFrameworkRelationalServicesBuilder.cs b/src/EFCore.Relational/Infrastructure/EntityFrameworkRelationalServicesBuilder.cs index 34dbfe4f6cf..7c511d32420 100644 --- a/src/EFCore.Relational/Infrastructure/EntityFrameworkRelationalServicesBuilder.cs +++ b/src/EFCore.Relational/Infrastructure/EntityFrameworkRelationalServicesBuilder.cs @@ -52,35 +52,35 @@ private static readonly IDictionary _relationalSer { typeof(IMigrationsIdGenerator), new ServiceCharacteristics(ServiceLifetime.Singleton) }, { typeof(ISqlGenerationHelper), new ServiceCharacteristics(ServiceLifetime.Singleton) }, { typeof(IRelationalAnnotationProvider), new ServiceCharacteristics(ServiceLifetime.Singleton) }, - { typeof(IMigrationsAnnotationProvider), new ServiceCharacteristics(ServiceLifetime.Scoped) }, + { typeof(IMigrationsAnnotationProvider), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IMigrationCommandExecutor), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IRelationalCommandBuilderFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IRawSqlCommandBuilder), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IMigrationsModelDiffer), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IMigrationsSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IRelationalTypeMapper), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IRelationalValueBufferFactoryFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IMaterializerFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IShaperCommandContextFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IConditionalRemovingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(ISelectExpressionFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IExpressionFragmentTranslator), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(ISqlTranslatingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IUpdateSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IMemberTranslator), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IMethodCallTranslator), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IQuerySqlGeneratorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(ICommandBatchPreparer), new ServiceCharacteristics(ServiceLifetime.Scoped) }, + { typeof(IModificationCommandBatchFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, + { typeof(IIncludeExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IMigrator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IMigrationCommandExecutor), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IMigrationsAssembly), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IBatchExecutor), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IRelationalCommandBuilderFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IRawSqlCommandBuilder), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(ICommandBatchPreparer), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IMigrationsModelDiffer), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IMigrationsSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IRelationalTypeMapper), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IRelationalValueBufferFactoryFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IMaterializerFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IShaperCommandContextFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IConditionalRemovingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(ICompositePredicateExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IIncludeExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(ISelectExpressionFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IRelationalResultOperatorHandler), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IExpressionFragmentTranslator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(ISqlTranslatingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IUpdateSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IModificationCommandBatchFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IRelationalConnection), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IRelationalDatabaseCreator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IHistoryRepository), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IMemberTranslator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IMethodCallTranslator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IQuerySqlGeneratorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) } + { typeof(IHistoryRepository), new ServiceCharacteristics(ServiceLifetime.Scoped) } }; /// @@ -162,25 +162,25 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices() .AddDependencySingleton() .AddDependencySingleton() .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() + .AddDependencySingleton() .AddDependencyScoped() - .AddDependencyScoped() - .AddDependencyScoped() .AddDependencyScoped() - .AddDependencyScoped() - .AddDependencyScoped() .AddDependencyScoped() - .AddDependencyScoped() .AddDependencyScoped() - .AddDependencyScoped() - .AddDependencyScoped() - .AddDependencyScoped() - .AddDependencyScoped() .AddDependencyScoped() .AddDependencyScoped() .AddDependencyScoped() .AddDependencyScoped() - .AddDependencyScoped() - .AddDependencyScoped() .AddDependencyScoped(); return base.TryAddCoreServices(); diff --git a/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs b/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs index 34cffe822cd..043c21ea18b 100644 --- a/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs +++ b/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs @@ -65,7 +65,18 @@ private static readonly IDictionary _coreServices { typeof(ISingletonOptionsInitialzer), new ServiceCharacteristics(ServiceLifetime.Singleton) }, { typeof(ILoggingOptions), new ServiceCharacteristics(ServiceLifetime.Singleton) }, { typeof(ISensitiveDataLogger<>), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IModelValidator), new ServiceCharacteristics(ServiceLifetime.Singleton) }, { typeof(ILogger<>), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(ICompiledQueryCache), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IQueryAnnotationExtractor), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IEntityTrackingInfoFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(ISubQueryMemberPushDownExpressionVisitor), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(ITaskBlockingExpressionVisitor), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IMemberAccessBindingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(INavigationRewritingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IQuerySourceTracingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IExpressionPrinter), new ServiceCharacteristics(ServiceLifetime.Singleton) }, + { typeof(IProjectionExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }, { typeof(IKeyPropagator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(INavigationFixer), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(ILocalViewListener), new ServiceCharacteristics(ServiceLifetime.Scoped) }, @@ -78,26 +89,15 @@ private static readonly IDictionary _coreServices { typeof(IDbContextServices), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IValueGeneratorSelector), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IConventionSetBuilder), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IModelValidator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IExecutionStrategyFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(ICompiledQueryCache), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IAsyncQueryProvider), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IQueryCompiler), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IQueryAnnotationExtractor), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IQueryOptimizer), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IEntityTrackingInfoFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(ISubQueryMemberPushDownExpressionVisitor), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(ITaskBlockingExpressionVisitor), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IEntityResultFindingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IMemberAccessBindingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(INavigationRewritingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IQuerySourceTracingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IRequiresMaterializationExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IExpressionPrinter), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IQueryCompilationContextFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(ICompiledQueryCacheKeyGenerator), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IResultOperatorHandler), new ServiceCharacteristics(ServiceLifetime.Scoped) }, - { typeof(IProjectionExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IModel), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(ICurrentDbContext), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IDbContextOptions), new ServiceCharacteristics(ServiceLifetime.Scoped) }, @@ -244,11 +244,11 @@ public virtual EntityFrameworkServicesBuilder TryAddCoreServices() .AddDependencySingleton() .AddDependencySingleton() .AddDependencySingleton() + .AddDependencySingleton() .AddDependency(typeof(SensitiveDataLoggerDependencies<>), ServiceLifetime.Singleton) .AddDependencyScoped() .AddDependencyScoped() .AddDependencyScoped() - .AddDependencyScoped() .AddDependencyScoped() .AddDependencyScoped() .AddDependencyScoped() diff --git a/test/EFCore.Sqlite.FunctionalTests/BadDataSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/BadDataSqliteTest.cs index ee1c7be6e6a..abf27e188bb 100644 --- a/test/EFCore.Sqlite.FunctionalTests/BadDataSqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/BadDataSqliteTest.cs @@ -363,7 +363,7 @@ private NorthwindContext CreateContext(params object[] values) var context = new NorthwindContext( _fixture.BuildOptions( new ServiceCollection() - .AddScoped())); + .AddSingleton())); var badDataCommandBuilderFactory = (BadDataCommandBuilderFactory)context.GetService();