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

Make more services singletons #8081

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,35 @@ private static readonly IDictionary<Type, ServiceCharacteristics> _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) }
};

/// <summary>
Expand Down Expand Up @@ -162,25 +162,25 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
.AddDependencySingleton<RelationalSqlGenerationHelperDependencies>()
.AddDependencySingleton<RelationalTypeMapperDependencies>()
.AddDependencySingleton<RelationalCompositeExpressionFragmentTranslatorDependencies>()
.AddDependencySingleton<RelationalModelValidatorDependencies>()
.AddDependencySingleton<UpdateSqlGeneratorDependencies>()
.AddDependencySingleton<QuerySqlGeneratorDependencies>()
.AddDependencySingleton<RelationalCompositeMethodCallTranslatorDependencies>()
.AddDependencySingleton<MigrationsSqlGeneratorDependencies>()
.AddDependencySingleton<MigrationsAnnotationProviderDependencies>()
.AddDependencySingleton<SqlTranslatingExpressionVisitorDependencies>()
.AddDependencySingleton<ParameterNameGeneratorDependencies>()
.AddDependencySingleton<SelectExpressionDependencies>()
.AddDependencySingleton<RelationalValueBufferFactoryDependencies>()
.AddDependencySingleton<RelationalProjectionExpressionVisitorDependencies>()
.AddDependencyScoped<RelationalConventionSetBuilderDependencies>()
.AddDependencyScoped<UpdateSqlGeneratorDependencies>()
.AddDependencyScoped<QuerySqlGeneratorDependencies>()
.AddDependencyScoped<RelationalDatabaseCreatorDependencies>()
.AddDependencyScoped<RelationalCompositeMethodCallTranslatorDependencies>()
.AddDependencyScoped<MigrationsSqlGeneratorDependencies>()
.AddDependencyScoped<HistoryRepositoryDependencies>()
.AddDependencyScoped<MigrationsAnnotationProviderDependencies>()
.AddDependencyScoped<RelationalCompiledQueryCacheKeyGeneratorDependencies>()
.AddDependencyScoped<RelationalModelValidatorDependencies>()
.AddDependencyScoped<SqlTranslatingExpressionVisitorDependencies>()
.AddDependencyScoped<RelationalProjectionExpressionVisitorDependencies>()
.AddDependencyScoped<ParameterNameGeneratorDependencies>()
.AddDependencyScoped<RelationalQueryModelVisitorDependencies>()
.AddDependencyScoped<RelationalEntityQueryableExpressionVisitorDependencies>()
.AddDependencyScoped<RelationalConnectionDependencies>()
.AddDependencyScoped<RelationalDatabaseDependencies>()
.AddDependencyScoped<SelectExpressionDependencies>()
.AddDependencyScoped<RelationalValueBufferFactoryDependencies>()
.AddDependencyScoped<RelationalQueryCompilationContextDependencies>();

return base.TryAddCoreServices();
Expand Down
24 changes: 12 additions & 12 deletions src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ private static readonly IDictionary<Type, ServiceCharacteristics> _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) },
Expand All @@ -78,26 +89,15 @@ private static readonly IDictionary<Type, ServiceCharacteristics> _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) },
Expand Down Expand Up @@ -244,11 +244,11 @@ public virtual EntityFrameworkServicesBuilder TryAddCoreServices()
.AddDependencySingleton<ResultOperatorHandlerDependencies>()
.AddDependencySingleton<ModelSourceDependencies>()
.AddDependencySingleton<ValueGeneratorCacheDependencies>()
.AddDependencySingleton<ModelValidatorDependencies>()
.AddDependency(typeof(SensitiveDataLoggerDependencies<>), ServiceLifetime.Singleton)
.AddDependencyScoped<ExecutionStrategyContextDependencies>()
.AddDependencyScoped<CompiledQueryCacheKeyGeneratorDependencies>()
.AddDependencyScoped<QueryContextDependencies>()
.AddDependencyScoped<ModelValidatorDependencies>()
.AddDependencyScoped<ValueGeneratorSelectorDependencies>()
.AddDependencyScoped<EntityQueryModelVisitorDependencies>()
.AddDependencyScoped<DatabaseDependencies>()
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Sqlite.FunctionalTests/BadDataSqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private NorthwindContext CreateContext(params object[] values)
var context = new NorthwindContext(
_fixture.BuildOptions(
new ServiceCollection()
.AddScoped<IRelationalCommandBuilderFactory, BadDataCommandBuilderFactory>()));
.AddSingleton<IRelationalCommandBuilderFactory, BadDataCommandBuilderFactory>()));

var badDataCommandBuilderFactory
= (BadDataCommandBuilderFactory)context.GetService<IRelationalCommandBuilderFactory>();
Expand Down