Skip to content

Commit 31773eb

Browse files
authored
Remove ISingletonUpdateSqlGenerator and make IUpdateSqlGenerator singleton (#14610)
Issue #10651
1 parent f0c5d1f commit 31773eb

File tree

7 files changed

+9
-34
lines changed

7 files changed

+9
-34
lines changed

src/EFCore.Relational/Infrastructure/EntityFrameworkRelationalServicesBuilder.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServi
7373
{ typeof(ISelectExpressionFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
7474
{ typeof(IExpressionFragmentTranslator), new ServiceCharacteristics(ServiceLifetime.Singleton) },
7575
{ typeof(ISqlTranslatingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
76-
{ typeof(IUpdateSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Scoped) },
77-
{ typeof(ISingletonUpdateSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Singleton) },
76+
{ typeof(IUpdateSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Singleton) },
7877
{ typeof(IMemberTranslator), new ServiceCharacteristics(ServiceLifetime.Singleton) },
7978
{ typeof(ICompositeMethodCallTranslator), new ServiceCharacteristics(ServiceLifetime.Singleton) },
8079
{ typeof(IQuerySqlGeneratorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
@@ -169,15 +168,6 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
169168
TryAdd<IEvaluatableExpressionFilter, RelationalEvaluatableExpressionFilter>();
170169
TryAdd<IRelationalTransactionFactory, RelationalTransactionFactory>();
171170

172-
TryAdd<ISingletonUpdateSqlGenerator>(
173-
p =>
174-
{
175-
using (var scope = p.CreateScope())
176-
{
177-
return scope.ServiceProvider.GetService<IUpdateSqlGenerator>();
178-
}
179-
});
180-
181171
ServiceCollectionMap.GetInfrastructure()
182172
.AddDependencySingleton<RelationalCompositeMemberTranslatorDependencies>()
183173
.AddDependencySingleton<RelationalSqlGenerationHelperDependencies>()

src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public MigrationsSqlGenerator([NotNull] MigrationsSqlGeneratorDependencies depen
8484
/// The <see cref="IUpdateSqlGenerator" />.
8585
/// </summary>
8686
protected virtual IUpdateSqlGenerator SqlGenerator
87-
=> (IUpdateSqlGenerator)Dependencies.UpdateSqlGenerator;
87+
=> Dependencies.UpdateSqlGenerator;
8888

8989
/// <summary>
9090
/// Gets a comparer that can be used to compare two product versions.

src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using JetBrains.Annotations;
55
using Microsoft.EntityFrameworkCore.Storage;
6+
using Microsoft.EntityFrameworkCore.Update;
67
using Microsoft.EntityFrameworkCore.Update.Internal;
78
using Microsoft.EntityFrameworkCore.Utilities;
89

@@ -50,7 +51,7 @@ public sealed class MigrationsSqlGeneratorDependencies
5051
/// <param name="typeMappingSource"> The type mapper. </param>
5152
public MigrationsSqlGeneratorDependencies(
5253
[NotNull] IRelationalCommandBuilderFactory commandBuilderFactory,
53-
[NotNull] ISingletonUpdateSqlGenerator updateSqlGenerator,
54+
[NotNull] IUpdateSqlGenerator updateSqlGenerator,
5455
[NotNull] ISqlGenerationHelper sqlGenerationHelper,
5556
[NotNull] IRelationalTypeMappingSource typeMappingSource)
5657
{
@@ -73,7 +74,7 @@ public MigrationsSqlGeneratorDependencies(
7374
/// <summary>
7475
/// High level SQL generator.
7576
/// </summary>
76-
public ISingletonUpdateSqlGenerator UpdateSqlGenerator { get; }
77+
public IUpdateSqlGenerator UpdateSqlGenerator { get; }
7778

7879
/// <summary>
7980
/// Helpers for SQL generation.
@@ -102,7 +103,7 @@ public MigrationsSqlGeneratorDependencies With([NotNull] IRelationalCommandBuild
102103
/// </summary>
103104
/// <param name="updateSqlGenerator"> A replacement for the current dependency of this type. </param>
104105
/// <returns> A new parameter object with the given service replaced. </returns>
105-
public MigrationsSqlGeneratorDependencies With([NotNull] ISingletonUpdateSqlGenerator updateSqlGenerator)
106+
public MigrationsSqlGeneratorDependencies With([NotNull] IUpdateSqlGenerator updateSqlGenerator)
106107
=> new MigrationsSqlGeneratorDependencies(
107108
CommandBuilderFactory,
108109
updateSqlGenerator,

src/EFCore.Relational/Update/IUpdateSqlGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Update
1616
/// This type is typically used by database providers; it is generally not used in application code.
1717
/// </para>
1818
/// </summary>
19-
public interface IUpdateSqlGenerator : ISingletonUpdateSqlGenerator
19+
public interface IUpdateSqlGenerator
2020
{
2121
/// <summary>
2222
/// Generates SQL that will obtain the next value in the given sequence.

src/EFCore.Relational/Update/Internal/ISingletonUpdateSqlGenerator.cs

-14
This file was deleted.

src/EFCore.SqlServer/Extensions/SqlServerServiceCollectionExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static class SqlServerServiceCollectionExtensions
5252
/// public void ConfigureServices(IServiceCollection services)
5353
/// {
5454
/// var connectionString = "connection string to database";
55-
///
55+
///
5656
/// services
5757
/// .AddEntityFrameworkSqlServer()
5858
/// .AddDbContext&lt;MyContext&gt;((serviceProvider, options) =>
@@ -78,7 +78,6 @@ public static IServiceCollection AddEntityFrameworkSqlServer([NotNull] this ISer
7878
.TryAdd<IModelValidator, SqlServerModelValidator>()
7979
.TryAdd<IConventionSetBuilder, SqlServerConventionSetBuilder>()
8080
.TryAdd<IUpdateSqlGenerator>(p => p.GetService<ISqlServerUpdateSqlGenerator>())
81-
.TryAdd<ISingletonUpdateSqlGenerator>(p => p.GetService<ISqlServerUpdateSqlGenerator>())
8281
.TryAdd<IModificationCommandBatchFactory, SqlServerModificationCommandBatchFactory>()
8382
.TryAdd<IValueGeneratorSelector, SqlServerValueGeneratorSelector>()
8483
.TryAdd<IRelationalConnection>(p => p.GetService<ISqlServerConnection>())

src/EFCore.Sqlite.Core/Infrastructure/SqliteServiceCollectionExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static class SqliteServiceCollectionExtensions
5050
/// public void ConfigureServices(IServiceCollection services)
5151
/// {
5252
/// var connectionString = "connection string to database";
53-
///
53+
///
5454
/// services
5555
/// .AddEntityFrameworkSqlite()
5656
/// .AddDbContext&lt;MyContext&gt;((serviceProvider, options) =>
@@ -75,7 +75,6 @@ public static IServiceCollection AddEntityFrameworkSqlite([NotNull] this IServic
7575
.TryAdd<IModelValidator, SqliteModelValidator>()
7676
.TryAdd<IConventionSetBuilder, SqliteConventionSetBuilder>()
7777
.TryAdd<IUpdateSqlGenerator, SqliteUpdateSqlGenerator>()
78-
.TryAdd<ISingletonUpdateSqlGenerator, SqliteUpdateSqlGenerator>()
7978
.TryAdd<IModificationCommandBatchFactory, SqliteModificationCommandBatchFactory>()
8079
.TryAdd<IRelationalConnection>(p => p.GetService<ISqliteRelationalConnection>())
8180
.TryAdd<IMigrationsSqlGenerator, SqliteMigrationsSqlGenerator>()

0 commit comments

Comments
 (0)