diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs index 7ee81a6abcb..a09756020d8 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs @@ -25,7 +25,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class CSharpMigrationOperationGeneratorDependencies + public sealed record CSharpMigrationOperationGeneratorDependencies { /// /// @@ -58,14 +58,6 @@ public CSharpMigrationOperationGeneratorDependencies([NotNull] ICSharpHelper csh /// /// The C# helper. /// - public ICSharpHelper CSharpHelper { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CSharpMigrationOperationGeneratorDependencies With([NotNull] ICSharpHelper csharpHelper) - => new CSharpMigrationOperationGeneratorDependencies(csharpHelper); + public ICSharpHelper CSharpHelper { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs index 9517a219310..a91338ef3be 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class CSharpMigrationsGeneratorDependencies + public sealed record CSharpMigrationsGeneratorDependencies { /// /// @@ -59,49 +59,16 @@ public CSharpMigrationsGeneratorDependencies( /// /// The C# helper. /// - public ICSharpHelper CSharpHelper { get; } + public ICSharpHelper CSharpHelper { get; [param: NotNull] init; } /// /// The C# migration operation generator. /// - public ICSharpMigrationOperationGenerator CSharpMigrationOperationGenerator { get; } + public ICSharpMigrationOperationGenerator CSharpMigrationOperationGenerator { get; [param: NotNull] init; } /// /// The C# model snapshot generator. /// - public ICSharpSnapshotGenerator CSharpSnapshotGenerator { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CSharpMigrationsGeneratorDependencies With([NotNull] ICSharpHelper csharpHelper) - => new CSharpMigrationsGeneratorDependencies( - csharpHelper, - CSharpMigrationOperationGenerator, - CSharpSnapshotGenerator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CSharpMigrationsGeneratorDependencies With([NotNull] ICSharpMigrationOperationGenerator csharpMigrationOperationGenerator) - => new CSharpMigrationsGeneratorDependencies( - CSharpHelper, - csharpMigrationOperationGenerator, - CSharpSnapshotGenerator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CSharpMigrationsGeneratorDependencies With([NotNull] ICSharpSnapshotGenerator csharpSnapshotGenerator) - => new CSharpMigrationsGeneratorDependencies( - CSharpHelper, - CSharpMigrationOperationGenerator, - csharpSnapshotGenerator); + public ICSharpSnapshotGenerator CSharpSnapshotGenerator { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs index 1b1a71caff5..a2cf3bb1eb3 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs @@ -26,7 +26,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class CSharpSnapshotGeneratorDependencies + public sealed record CSharpSnapshotGeneratorDependencies { /// /// @@ -63,40 +63,16 @@ public CSharpSnapshotGeneratorDependencies( /// /// The C# helper. /// - public ICSharpHelper CSharpHelper { get; } + public ICSharpHelper CSharpHelper { get; [param: NotNull] init; } /// /// The type mapper. /// - public IRelationalTypeMappingSource RelationalTypeMappingSource { get; } + public IRelationalTypeMappingSource RelationalTypeMappingSource { get; [param: NotNull] init; } /// /// The annotation code generator. /// - public IAnnotationCodeGenerator AnnotationCodeGenerator { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CSharpSnapshotGeneratorDependencies With([NotNull] ICSharpHelper csharpHelper) - => new CSharpSnapshotGeneratorDependencies(csharpHelper, RelationalTypeMappingSource, AnnotationCodeGenerator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CSharpSnapshotGeneratorDependencies With([NotNull] IRelationalTypeMappingSource relationalTypeMappingSource) - => new CSharpSnapshotGeneratorDependencies(CSharpHelper, relationalTypeMappingSource, AnnotationCodeGenerator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CSharpSnapshotGeneratorDependencies With([NotNull] IAnnotationCodeGenerator annotationCodeGenerator) - => new CSharpSnapshotGeneratorDependencies(CSharpHelper, RelationalTypeMappingSource, annotationCodeGenerator); + public IAnnotationCodeGenerator AnnotationCodeGenerator { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs index 74ee7f6f284..1746a7b367f 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs @@ -25,7 +25,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class MigrationsCodeGeneratorDependencies + public sealed record MigrationsCodeGeneratorDependencies { /// /// @@ -58,27 +58,11 @@ public MigrationsCodeGeneratorDependencies( /// /// The type mapper. /// - public IRelationalTypeMappingSource RelationalTypeMappingSource { get; } + public IRelationalTypeMappingSource RelationalTypeMappingSource { get; [param: NotNull] init; } /// /// The annotation code generator. /// - public IAnnotationCodeGenerator AnnotationCodeGenerator { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsCodeGeneratorDependencies With([NotNull] IRelationalTypeMappingSource relationalTypeMappingSource) - => new MigrationsCodeGeneratorDependencies(relationalTypeMappingSource, AnnotationCodeGenerator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsCodeGeneratorDependencies With([NotNull] IAnnotationCodeGenerator annotationCodeGenerator) - => new MigrationsCodeGeneratorDependencies(RelationalTypeMappingSource, annotationCodeGenerator); + public IAnnotationCodeGenerator AnnotationCodeGenerator { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs b/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs index d6f0d7c848a..1b2fa18d4e3 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs @@ -28,7 +28,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class MigrationsScaffolderDependencies + public sealed record MigrationsScaffolderDependencies { /// /// @@ -97,269 +97,58 @@ public MigrationsScaffolderDependencies( /// /// The current DbContext. /// - public ICurrentDbContext CurrentContext { get; } + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } /// /// The model. /// - public IModel Model { get; } + public IModel Model { get; [param: NotNull] init; } /// /// The migrations assembly. /// - public IMigrationsAssembly MigrationsAssembly { get; } + public IMigrationsAssembly MigrationsAssembly { get; [param: NotNull] init; } /// /// The migrations model differ. /// - public IMigrationsModelDiffer MigrationsModelDiffer { get; } + public IMigrationsModelDiffer MigrationsModelDiffer { get; [param: NotNull] init; } /// /// The migrations ID generator. /// - public IMigrationsIdGenerator MigrationsIdGenerator { get; } + public IMigrationsIdGenerator MigrationsIdGenerator { get; [param: NotNull] init; } /// /// The migrations code generator selector. /// - public IMigrationsCodeGeneratorSelector MigrationsCodeGeneratorSelector { get; } + public IMigrationsCodeGeneratorSelector MigrationsCodeGeneratorSelector { get; [param: NotNull] init; } /// /// The history repository. /// - public IHistoryRepository HistoryRepository { get; } + public IHistoryRepository HistoryRepository { get; [param: NotNull] init; } /// /// The operation reporter. /// [EntityFrameworkInternal] - public IOperationReporter OperationReporter { get; } + public IOperationReporter OperationReporter { get; [param: NotNull] init; } /// /// The database provider. /// - public IDatabaseProvider DatabaseProvider { get; } + public IDatabaseProvider DatabaseProvider { get; [param: NotNull] init; } /// /// The snapshot model processor. /// [EntityFrameworkInternal] - public ISnapshotModelProcessor SnapshotModelProcessor { get; } + public ISnapshotModelProcessor SnapshotModelProcessor { get; [param: NotNull] init; } /// /// The migrator. /// - public IMigrator Migrator { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] ICurrentDbContext currentContext) - => new MigrationsScaffolderDependencies( - currentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IModel model) - => new MigrationsScaffolderDependencies( - CurrentContext, - model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IMigrationsAssembly migrationsAssembly) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - migrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IMigrationsModelDiffer migrationsModelDiffer) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - migrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IMigrationsIdGenerator migrationsIdGenerator) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - migrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IMigrationsCodeGeneratorSelector migrationsCodeGeneratorSelector) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - migrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IHistoryRepository historyRepository) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - historyRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - [EntityFrameworkInternal] - public MigrationsScaffolderDependencies With([NotNull] IOperationReporter operationReporter) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - operationReporter, - DatabaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IDatabaseProvider databaseProvider) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - databaseProvider, - SnapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - [EntityFrameworkInternal] - public MigrationsScaffolderDependencies With([NotNull] ISnapshotModelProcessor snapshotModelProcessor) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - snapshotModelProcessor, - Migrator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsScaffolderDependencies With([NotNull] IMigrator migrator) - => new MigrationsScaffolderDependencies( - CurrentContext, - Model, - MigrationsAssembly, - MigrationsModelDiffer, - MigrationsIdGenerator, - MigrationsCodeGeneratorSelector, - HistoryRepository, - OperationReporter, - DatabaseProvider, - SnapshotModelProcessor, - migrator); + public IMigrator Migrator { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs b/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs index fd082781cc9..c47fda96bf4 100644 --- a/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs +++ b/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs @@ -22,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class ModelCodeGeneratorDependencies + public sealed record ModelCodeGeneratorDependencies { /// /// diff --git a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs index fa75e94ec00..ee20a777691 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs @@ -25,7 +25,7 @@ namespace Microsoft.EntityFrameworkCore.Design /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class AnnotationCodeGeneratorDependencies + public sealed record AnnotationCodeGeneratorDependencies { /// /// @@ -58,6 +58,6 @@ public AnnotationCodeGeneratorDependencies( /// /// The type mapper. /// - public IRelationalTypeMappingSource RelationalTypeMappingSource { get; } + public IRelationalTypeMappingSource RelationalTypeMappingSource { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs b/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs index 13b4cb5664d..85abc4d2a34 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// This service cannot depend on services registered as . /// /// - public sealed class RelationalModelValidatorDependencies + public sealed record RelationalModelValidatorDependencies { /// /// @@ -68,14 +68,6 @@ public RelationalModelValidatorDependencies( /// /// The type mapper. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalModelValidatorDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new RelationalModelValidatorDependencies(typeMappingSource); + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs index da0feadbae2..46b2e28feba 100644 --- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs +++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalConventionSetBuilderDependencies + public sealed record RelationalConventionSetBuilderDependencies { /// /// @@ -69,14 +69,6 @@ public RelationalConventionSetBuilderDependencies([NotNull] IRelationalAnnotatio /// /// The relational annotation provider. /// - public IRelationalAnnotationProvider RelationalAnnotationProvider { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalConventionSetBuilderDependencies With([NotNull] IRelationalAnnotationProvider relationalAnnotationProvider) - => new RelationalConventionSetBuilderDependencies(relationalAnnotationProvider); + public IRelationalAnnotationProvider RelationalAnnotationProvider { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs b/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs index 87318114eee..9e39942810f 100644 --- a/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs +++ b/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs @@ -35,7 +35,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - public sealed class RelationalAnnotationProviderDependencies + public sealed record RelationalAnnotationProviderDependencies { /// /// diff --git a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs index 999ae59f410..a70b2832bb4 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs @@ -43,7 +43,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// The implementation does not need to be thread-safe. /// /// - public sealed class HistoryRepositoryDependencies + public sealed record HistoryRepositoryDependencies { /// /// @@ -120,343 +120,67 @@ public HistoryRepositoryDependencies( /// /// The database creator. /// - public IRelationalDatabaseCreator DatabaseCreator { get; } + public IRelationalDatabaseCreator DatabaseCreator { get; [param: NotNull] init; } /// /// A command builder for building raw SQL commands. /// - public IRawSqlCommandBuilder RawSqlCommandBuilder { get; } + public IRawSqlCommandBuilder RawSqlCommandBuilder { get; [param: NotNull] init; } /// /// The connection to the database. /// - public IRelationalConnection Connection { get; } + public IRelationalConnection Connection { get; [param: NotNull] init; } /// /// Options for the current context instance. /// - public IDbContextOptions Options { get; } + public IDbContextOptions Options { get; [param: NotNull] init; } /// /// The model differ. /// - public IMigrationsModelDiffer ModelDiffer { get; } + public IMigrationsModelDiffer ModelDiffer { get; [param: NotNull] init; } /// /// The SQL generator for Migrations operations. /// - public IMigrationsSqlGenerator MigrationsSqlGenerator { get; } + public IMigrationsSqlGenerator MigrationsSqlGenerator { get; [param: NotNull] init; } /// /// Helpers for generating update SQL. /// - public ISqlGenerationHelper SqlGenerationHelper { get; } + public ISqlGenerationHelper SqlGenerationHelper { get; [param: NotNull] init; } /// /// The core convention set to use when creating the model. /// - public IConventionSetBuilder ConventionSetBuilder { get; } + public IConventionSetBuilder ConventionSetBuilder { get; [param: NotNull] init; } /// /// The model dependencies. /// - public ModelDependencies ModelDependencies { get; } + public ModelDependencies ModelDependencies { get; [param: NotNull] init; } /// /// The type mapper. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// Contains the currently in use. /// - public ICurrentDbContext CurrentContext { get; } + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } /// /// The model logger /// [Obsolete] - public IDiagnosticsLogger ModelLogger { get; } + public IDiagnosticsLogger ModelLogger { get; [param: NotNull] init; } /// /// The command logger /// - public IDiagnosticsLogger CommandLogger { get; } - -#pragma warning disable CS0612 // Type or member is obsolete - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IRelationalDatabaseCreator databaseCreator) - => new HistoryRepositoryDependencies( - databaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder) - => new HistoryRepositoryDependencies( - DatabaseCreator, - rawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IRelationalConnection connection) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IDbContextOptions options) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IMigrationsModelDiffer modelDiffer) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - modelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IMigrationsSqlGenerator migrationsSqlGenerator) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - migrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - sqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// The core convention set to use when creating the model. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IConventionSetBuilder conventionSetBuilder) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - conventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// The core convention set to use when creating the model. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] ModelDependencies modelDependencies) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - modelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// The type mapper. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - typeMappingSource, - CurrentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// The type mapper. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] ICurrentDbContext currentContext) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - currentContext, - ModelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// The type mapper. - /// A new parameter object with the given service replaced. - [Obsolete] - public HistoryRepositoryDependencies With([NotNull] IDiagnosticsLogger modelLogger) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies.With(modelLogger), - TypeMappingSource, - CurrentContext, - modelLogger, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// The command logger. - /// A new parameter object with the given service replaced. - public HistoryRepositoryDependencies With([NotNull] IDiagnosticsLogger commandLogger) - => new HistoryRepositoryDependencies( - DatabaseCreator, - RawSqlCommandBuilder, - Connection, - Options, - ModelDiffer, - MigrationsSqlGenerator, - SqlGenerationHelper, - ConventionSetBuilder, - ModelDependencies, - TypeMappingSource, - CurrentContext, - ModelLogger, - commandLogger); -#pragma warning restore CS0612 // Type or member is obsolete + public IDiagnosticsLogger CommandLogger { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs b/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs index ff879f8bdfc..85525c3abd1 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs @@ -36,7 +36,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// /// [EntityFrameworkInternal] - public sealed class MigrationsAnnotationProviderDependencies + public sealed record MigrationsAnnotationProviderDependencies { /// /// diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs index 56646f51847..4381134d0d6 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs @@ -34,7 +34,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// The implementation does not need to be thread-safe. /// /// - public sealed class MigrationsSqlGeneratorDependencies + public sealed record MigrationsSqlGeneratorDependencies { /// /// @@ -88,169 +88,41 @@ public MigrationsSqlGeneratorDependencies( /// /// The command builder factory. /// - public IRelationalCommandBuilderFactory CommandBuilderFactory { get; } + public IRelationalCommandBuilderFactory CommandBuilderFactory { get; [param: NotNull] init; } /// /// High level SQL generator. /// - public IUpdateSqlGenerator UpdateSqlGenerator { get; } + public IUpdateSqlGenerator UpdateSqlGenerator { get; [param: NotNull] init; } /// /// Helpers for SQL generation. /// - public ISqlGenerationHelper SqlGenerationHelper { get; } + public ISqlGenerationHelper SqlGenerationHelper { get; [param: NotNull] init; } /// /// The type mapper. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// Contains the currently in use. /// - public ICurrentDbContext CurrentContext { get; } + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } /// /// The logging options. /// - public ILoggingOptions LoggingOptions { get; } + public ILoggingOptions LoggingOptions { get; [param: NotNull] init; } /// /// The database command logger. /// - public IDiagnosticsLogger Logger { get; } + public IDiagnosticsLogger Logger { get; [param: NotNull] init; } /// /// The database command logger. /// - public IDiagnosticsLogger MigrationsLogger { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] IRelationalCommandBuilderFactory commandBuilderFactory) - => new MigrationsSqlGeneratorDependencies( - commandBuilderFactory, - UpdateSqlGenerator, - SqlGenerationHelper, - TypeMappingSource, - CurrentContext, - LoggingOptions, - Logger, - MigrationsLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] IUpdateSqlGenerator updateSqlGenerator) - => new MigrationsSqlGeneratorDependencies( - CommandBuilderFactory, - updateSqlGenerator, - SqlGenerationHelper, - TypeMappingSource, - CurrentContext, - LoggingOptions, - Logger, - MigrationsLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper) - => new MigrationsSqlGeneratorDependencies( - CommandBuilderFactory, - UpdateSqlGenerator, - sqlGenerationHelper, - TypeMappingSource, - CurrentContext, - LoggingOptions, - Logger, - MigrationsLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new MigrationsSqlGeneratorDependencies( - CommandBuilderFactory, - UpdateSqlGenerator, - SqlGenerationHelper, - typeMappingSource, - CurrentContext, - LoggingOptions, - Logger, - MigrationsLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] ICurrentDbContext currentContext) - => new MigrationsSqlGeneratorDependencies( - CommandBuilderFactory, - UpdateSqlGenerator, - SqlGenerationHelper, - TypeMappingSource, - currentContext, - LoggingOptions, - Logger, - MigrationsLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] ILoggingOptions loggingOptions) - => new MigrationsSqlGeneratorDependencies( - CommandBuilderFactory, - UpdateSqlGenerator, - SqlGenerationHelper, - TypeMappingSource, - CurrentContext, - loggingOptions, - Logger, - MigrationsLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] IDiagnosticsLogger logger) - => new MigrationsSqlGeneratorDependencies( - CommandBuilderFactory, - UpdateSqlGenerator, - SqlGenerationHelper, - TypeMappingSource, - CurrentContext, - LoggingOptions, - logger, - MigrationsLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public MigrationsSqlGeneratorDependencies With([NotNull] IDiagnosticsLogger migrationsLogger) - => new MigrationsSqlGeneratorDependencies( - CommandBuilderFactory, - UpdateSqlGenerator, - SqlGenerationHelper, - TypeMappingSource, - CurrentContext, - LoggingOptions, - Logger, - migrationsLogger); + public IDiagnosticsLogger MigrationsLogger { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs index f9a5a4ca9e9..bcc1f426d05 100644 --- a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class QuerySqlGeneratorDependencies + public sealed record QuerySqlGeneratorDependencies { /// /// @@ -69,27 +69,11 @@ public QuerySqlGeneratorDependencies( /// /// The command-builder factory. /// - public IRelationalCommandBuilderFactory RelationalCommandBuilderFactory { get; } + public IRelationalCommandBuilderFactory RelationalCommandBuilderFactory { get; [param: NotNull] init; } /// /// SQL generation helpers. /// - public ISqlGenerationHelper SqlGenerationHelper { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QuerySqlGeneratorDependencies With([NotNull] IRelationalCommandBuilderFactory relationalCommandBuilderFactory) - => new QuerySqlGeneratorDependencies(relationalCommandBuilderFactory, SqlGenerationHelper); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QuerySqlGeneratorDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper) - => new QuerySqlGeneratorDependencies(RelationalCommandBuilderFactory, sqlGenerationHelper); + public ISqlGenerationHelper SqlGenerationHelper { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs index ec1298e806a..e5fc8e64e45 100644 --- a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalCompiledQueryCacheKeyGeneratorDependencies + public sealed record RelationalCompiledQueryCacheKeyGeneratorDependencies { /// /// @@ -69,14 +69,6 @@ public RelationalCompiledQueryCacheKeyGeneratorDependencies([NotNull] IDbContext /// /// Options for the current instance. /// - public IDbContextOptions ContextOptions { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalCompiledQueryCacheKeyGeneratorDependencies With([NotNull] IDbContextOptions contextOptions) - => new RelationalCompiledQueryCacheKeyGeneratorDependencies(contextOptions); + public IDbContextOptions ContextOptions { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs index a871fda6bcd..92368e01428 100644 --- a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs @@ -30,7 +30,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalEvaluatableExpressionFilterDependencies + public sealed record RelationalEvaluatableExpressionFilterDependencies { /// /// diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs index 721800b2c1d..7a6b7a02162 100644 --- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalMemberTranslatorProviderDependencies + public sealed record RelationalMemberTranslatorProviderDependencies { /// /// @@ -69,27 +69,11 @@ public RelationalMemberTranslatorProviderDependencies( /// /// The expression factory.. /// - public ISqlExpressionFactory SqlExpressionFactory { get; } + public ISqlExpressionFactory SqlExpressionFactory { get; [param: NotNull] init; } /// /// Registered plugins. /// - public IEnumerable Plugins { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalMemberTranslatorProviderDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalMemberTranslatorProviderDependencies(sqlExpressionFactory, Plugins); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalMemberTranslatorProviderDependencies With([NotNull] IEnumerable plugins) - => new RelationalMemberTranslatorProviderDependencies(SqlExpressionFactory, plugins); + public IEnumerable Plugins { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs index ef87364bbdd..5a724cdb605 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs @@ -34,7 +34,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalMethodCallTranslatorProviderDependencies + public sealed record RelationalMethodCallTranslatorProviderDependencies { /// /// @@ -73,40 +73,16 @@ public RelationalMethodCallTranslatorProviderDependencies( /// /// The expression factory.. /// - public ISqlExpressionFactory SqlExpressionFactory { get; } + public ISqlExpressionFactory SqlExpressionFactory { get; [param: NotNull] init; } /// /// Registered plugins. /// - public IEnumerable Plugins { get; } + public IEnumerable Plugins { get; [param: NotNull] init; } /// /// Relational Type Mapping Source. /// - public IRelationalTypeMappingSource RelationalTypeMappingSource { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalMethodCallTranslatorProviderDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalMethodCallTranslatorProviderDependencies(sqlExpressionFactory, Plugins, RelationalTypeMappingSource); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalMethodCallTranslatorProviderDependencies With([NotNull] IEnumerable plugins) - => new RelationalMethodCallTranslatorProviderDependencies(SqlExpressionFactory, plugins, RelationalTypeMappingSource); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalMethodCallTranslatorProviderDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new RelationalMethodCallTranslatorProviderDependencies(SqlExpressionFactory, Plugins, typeMappingSource); + public IRelationalTypeMappingSource RelationalTypeMappingSource { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs index 0a322657104..24933400de8 100644 --- a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs @@ -34,7 +34,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalParameterBasedSqlProcessorDependencies + public sealed record RelationalParameterBasedSqlProcessorDependencies { /// /// @@ -73,40 +73,16 @@ public RelationalParameterBasedSqlProcessorDependencies( /// /// Sql expression factory. /// - public ISqlExpressionFactory SqlExpressionFactory { get; } + public ISqlExpressionFactory SqlExpressionFactory { get; [param: NotNull] init; } /// /// Relational type mapping souce. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// Parameter name generator factory. /// - public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalParameterBasedSqlProcessorDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalParameterBasedSqlProcessorDependencies(sqlExpressionFactory, TypeMappingSource, ParameterNameGeneratorFactory); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalParameterBasedSqlProcessorDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new RelationalParameterBasedSqlProcessorDependencies(SqlExpressionFactory, typeMappingSource, ParameterNameGeneratorFactory); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalParameterBasedSqlProcessorDependencies With([NotNull] IParameterNameGeneratorFactory parameterNameGeneratorFactory) - => new RelationalParameterBasedSqlProcessorDependencies(SqlExpressionFactory, TypeMappingSource, parameterNameGeneratorFactory); + public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs index 5ad66d1907f..44b43ac71ec 100644 --- a/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalQueryCompilationContextDependencies + public sealed record RelationalQueryCompilationContextDependencies { /// /// diff --git a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs index 1f30abaebe7..b38bf9f4421 100644 --- a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs @@ -35,7 +35,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalQueryContextDependencies + public sealed record RelationalQueryContextDependencies { /// /// @@ -71,27 +71,11 @@ public RelationalQueryContextDependencies( /// /// The connection. /// - public IRelationalConnection RelationalConnection { get; } + public IRelationalConnection RelationalConnection { get; [param: NotNull] init; } /// /// A factory for creating a readable query string from a /// - public IRelationalQueryStringFactory RelationalQueryStringFactory { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalQueryContextDependencies With([NotNull] IRelationalConnection relationalConnection) - => new RelationalQueryContextDependencies(relationalConnection, RelationalQueryStringFactory); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalQueryContextDependencies With([NotNull] IRelationalQueryStringFactory relationalQueryStringFactory) - => new RelationalQueryContextDependencies(RelationalConnection, relationalQueryStringFactory); + public IRelationalQueryStringFactory RelationalQueryStringFactory { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs index 70b0f9df8f5..c047735685d 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalQueryTranslationPostprocessorDependencies + public sealed record RelationalQueryTranslationPostprocessorDependencies { /// /// @@ -64,14 +64,6 @@ public RelationalQueryTranslationPostprocessorDependencies( /// /// The SQL expression factory. /// - public ISqlExpressionFactory SqlExpressionFactory { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalQueryTranslationPostprocessorDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalQueryTranslationPostprocessorDependencies(sqlExpressionFactory); + public ISqlExpressionFactory SqlExpressionFactory { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs index d7f877d3a70..1f6cff1edc6 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs @@ -30,7 +30,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalQueryTranslationPreprocessorDependencies + public sealed record RelationalQueryTranslationPreprocessorDependencies { /// /// diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs index 70d5c283dec..98ddbd3f56c 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalQueryableMethodTranslatingExpressionVisitorDependencies + public sealed record RelationalQueryableMethodTranslatingExpressionVisitorDependencies { /// /// @@ -68,30 +68,15 @@ public RelationalQueryableMethodTranslatingExpressionVisitorDependencies( /// /// The SQL-translating expression visitor factory. /// - public IRelationalSqlTranslatingExpressionVisitorFactory RelationalSqlTranslatingExpressionVisitorFactory { get; } + public IRelationalSqlTranslatingExpressionVisitorFactory RelationalSqlTranslatingExpressionVisitorFactory + { + get; + [param: NotNull] init; + } /// /// The SQL expression factory. /// - public ISqlExpressionFactory SqlExpressionFactory { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalQueryableMethodTranslatingExpressionVisitorDependencies With( - [NotNull] IRelationalSqlTranslatingExpressionVisitorFactory relationalSqlTranslatingExpressionVisitorFactory) - => new RelationalQueryableMethodTranslatingExpressionVisitorDependencies( - relationalSqlTranslatingExpressionVisitorFactory, SqlExpressionFactory); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalQueryableMethodTranslatingExpressionVisitorDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalQueryableMethodTranslatingExpressionVisitorDependencies( - RelationalSqlTranslatingExpressionVisitorFactory, sqlExpressionFactory); + public ISqlExpressionFactory SqlExpressionFactory { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs index a8ac8c8f2b3..4b36639edbf 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs @@ -35,7 +35,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalShapedQueryCompilingExpressionVisitorDependencies + public sealed record RelationalShapedQueryCompilingExpressionVisitorDependencies { /// /// @@ -81,107 +81,28 @@ public RelationalShapedQueryCompilingExpressionVisitorDependencies( /// /// The SQL generator factory. /// - public IQuerySqlGeneratorFactory QuerySqlGeneratorFactory { get; } + public IQuerySqlGeneratorFactory QuerySqlGeneratorFactory { get; [param: NotNull] init; } /// /// The SQL expression factory. /// [Obsolete("Use the service from " + nameof(RelationalParameterBasedSqlProcessorDependencies) + ".")] - public ISqlExpressionFactory SqlExpressionFactory { get; } + public ISqlExpressionFactory SqlExpressionFactory { get; [param: NotNull] init; } /// /// The parameter name-generator factory. /// [Obsolete("Use the service from " + nameof(RelationalParameterBasedSqlProcessorDependencies) + ".")] - public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; } + public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; [param: NotNull] init; } /// /// The SQL processor based on parameter values. /// - public IRelationalParameterBasedSqlProcessorFactory RelationalParameterBasedSqlProcessorFactory { get; } + public IRelationalParameterBasedSqlProcessorFactory RelationalParameterBasedSqlProcessorFactory { get; [param: NotNull] init; } /// /// Core singleton options. /// - public ICoreSingletonOptions CoreSingletonOptions { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalShapedQueryCompilingExpressionVisitorDependencies With( - [NotNull] IQuerySqlGeneratorFactory querySqlGeneratorFactory) - => new RelationalShapedQueryCompilingExpressionVisitorDependencies( - querySqlGeneratorFactory, -#pragma warning disable CS0618 // Type or member is obsolete - SqlExpressionFactory, - ParameterNameGeneratorFactory, -#pragma warning restore CS0618 // Type or member is obsolete - RelationalParameterBasedSqlProcessorFactory, - CoreSingletonOptions); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalShapedQueryCompilingExpressionVisitorDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalShapedQueryCompilingExpressionVisitorDependencies( - QuerySqlGeneratorFactory, - sqlExpressionFactory, -#pragma warning disable CS0618 // Type or member is obsolete - ParameterNameGeneratorFactory, -#pragma warning restore CS0618 // Type or member is obsolete - RelationalParameterBasedSqlProcessorFactory, - CoreSingletonOptions); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalShapedQueryCompilingExpressionVisitorDependencies With( - [NotNull] IParameterNameGeneratorFactory parameterNameGeneratorFactory) - => new RelationalShapedQueryCompilingExpressionVisitorDependencies( - QuerySqlGeneratorFactory, -#pragma warning disable CS0618 // Type or member is obsolete - SqlExpressionFactory, -#pragma warning restore CS0618 // Type or member is obsolete - parameterNameGeneratorFactory, - RelationalParameterBasedSqlProcessorFactory, - CoreSingletonOptions); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalShapedQueryCompilingExpressionVisitorDependencies With( - [NotNull] IRelationalParameterBasedSqlProcessorFactory relationalParameterBasedSqlProcessorFactory) - => new RelationalShapedQueryCompilingExpressionVisitorDependencies( - QuerySqlGeneratorFactory, -#pragma warning disable CS0618 // Type or member is obsolete - SqlExpressionFactory, - ParameterNameGeneratorFactory, -#pragma warning restore CS0618 // Type or member is obsolete - relationalParameterBasedSqlProcessorFactory, - CoreSingletonOptions); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalShapedQueryCompilingExpressionVisitorDependencies With( - [NotNull] ICoreSingletonOptions coreSingletonOptions) - => new RelationalShapedQueryCompilingExpressionVisitorDependencies( - QuerySqlGeneratorFactory, -#pragma warning disable CS0618 // Type or member is obsolete - SqlExpressionFactory, - ParameterNameGeneratorFactory, -#pragma warning restore CS0618 // Type or member is obsolete - RelationalParameterBasedSqlProcessorFactory, - coreSingletonOptions); + public ICoreSingletonOptions CoreSingletonOptions { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs index eb3c9cacb59..460a6308fde 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class RelationalSqlTranslatingExpressionVisitorDependencies + public sealed record RelationalSqlTranslatingExpressionVisitorDependencies { /// /// @@ -75,58 +75,21 @@ public RelationalSqlTranslatingExpressionVisitorDependencies( /// /// The expression factory. /// - public ISqlExpressionFactory SqlExpressionFactory { get; } + public ISqlExpressionFactory SqlExpressionFactory { get; [param: NotNull] init; } /// /// The relational type mapping souce. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// The member translation provider. /// - public IMemberTranslatorProvider MemberTranslatorProvider { get; } + public IMemberTranslatorProvider MemberTranslatorProvider { get; [param: NotNull] init; } /// /// The method-call translation provider. /// - public IMethodCallTranslatorProvider MethodCallTranslatorProvider { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalSqlTranslatingExpressionVisitorDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalSqlTranslatingExpressionVisitorDependencies( - sqlExpressionFactory, TypeMappingSource, MemberTranslatorProvider, MethodCallTranslatorProvider); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalSqlTranslatingExpressionVisitorDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new RelationalSqlTranslatingExpressionVisitorDependencies( - SqlExpressionFactory, typeMappingSource, MemberTranslatorProvider, MethodCallTranslatorProvider); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalSqlTranslatingExpressionVisitorDependencies With([NotNull] IMemberTranslatorProvider memberTranslatorProvider) - => new RelationalSqlTranslatingExpressionVisitorDependencies( - SqlExpressionFactory, TypeMappingSource, memberTranslatorProvider, MethodCallTranslatorProvider); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalSqlTranslatingExpressionVisitorDependencies With( - [NotNull] IMethodCallTranslatorProvider methodCallTranslatorProvider) - => new RelationalSqlTranslatingExpressionVisitorDependencies( - SqlExpressionFactory, TypeMappingSource, MemberTranslatorProvider, methodCallTranslatorProvider); + public IMethodCallTranslatorProvider MethodCallTranslatorProvider { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs index eac04fa5f32..60112f13675 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class SqlExpressionFactoryDependencies + public sealed record SqlExpressionFactoryDependencies { /// /// @@ -65,14 +65,6 @@ public SqlExpressionFactoryDependencies([NotNull] IRelationalTypeMappingSource t /// /// The type mapping source. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public SqlExpressionFactoryDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new SqlExpressionFactoryDependencies(typeMappingSource); + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs index 6b5f40b1c4d..bc24f0cafb4 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs @@ -25,7 +25,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - public sealed class ProviderCodeGeneratorDependencies + public sealed record ProviderCodeGeneratorDependencies { /// /// @@ -57,14 +57,6 @@ public ProviderCodeGeneratorDependencies([NotNull] IEnumerable /// Gets the plugins. /// - public IEnumerable Plugins { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderCodeGeneratorDependencies With([NotNull] IEnumerable plugins) - => new ProviderCodeGeneratorDependencies(plugins); + public IEnumerable Plugins { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/Internal/RelationalDatabaseFacadeDependencies.cs b/src/EFCore.Relational/Storage/Internal/RelationalDatabaseFacadeDependencies.cs index faecbfe124b..e4d8c59f9d2 100644 --- a/src/EFCore.Relational/Storage/Internal/RelationalDatabaseFacadeDependencies.cs +++ b/src/EFCore.Relational/Storage/Internal/RelationalDatabaseFacadeDependencies.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class RelationalDatabaseFacadeDependencies : IRelationalDatabaseFacadeDependencies + public record RelationalDatabaseFacadeDependencies : IRelationalDatabaseFacadeDependencies { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -48,7 +48,7 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IDbContextTransactionManager TransactionManager { get; } + public virtual IDbContextTransactionManager TransactionManager { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -56,7 +56,7 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IDatabaseCreator DatabaseCreator { get; } + public virtual IDatabaseCreator DatabaseCreator { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -64,7 +64,7 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IExecutionStrategyFactory ExecutionStrategyFactory { get; } + public virtual IExecutionStrategyFactory ExecutionStrategyFactory { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -72,7 +72,7 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IEnumerable DatabaseProviders { get; } + public virtual IEnumerable DatabaseProviders { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -80,7 +80,7 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IDiagnosticsLogger CommandLogger { get; } + public virtual IDiagnosticsLogger CommandLogger { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -88,7 +88,7 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IConcurrencyDetector ConcurrencyDetector { get; } + public virtual IConcurrencyDetector ConcurrencyDetector { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -96,7 +96,7 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IRelationalConnection RelationalConnection { get; } + public virtual IRelationalConnection RelationalConnection { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -104,6 +104,6 @@ public RelationalDatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IRawSqlCommandBuilder RawSqlCommandBuilder { get; } + public virtual IRawSqlCommandBuilder RawSqlCommandBuilder { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs b/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs index 8001a00955f..3615bc407a6 100644 --- a/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs +++ b/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class ParameterNameGeneratorDependencies + public sealed record ParameterNameGeneratorDependencies { /// /// diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs index f33d7f71b81..8f8a716d7df 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs @@ -30,7 +30,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class RelationalCommandBuilderDependencies + public sealed record RelationalCommandBuilderDependencies { /// /// @@ -63,14 +63,6 @@ public RelationalCommandBuilderDependencies( /// /// The source for s to use. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalCommandBuilderDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new RelationalCommandBuilderDependencies(typeMappingSource); + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs b/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs index b6c8b9faead..ddb7bb57954 100644 --- a/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalConnectionDependencies + public sealed record RelationalConnectionDependencies { /// /// @@ -81,117 +81,32 @@ public RelationalConnectionDependencies( /// /// The options for the current context instance. /// - public IDbContextOptions ContextOptions { get; } + public IDbContextOptions ContextOptions { get; [param: NotNull] init; } /// /// The logger to which transaction messages will be written. /// - public IDiagnosticsLogger TransactionLogger { get; } + public IDiagnosticsLogger TransactionLogger { get; [param: NotNull] init; } /// /// The logger to which connection messages will be written. /// - public IDiagnosticsLogger ConnectionLogger { get; } + public IDiagnosticsLogger ConnectionLogger { get; [param: NotNull] init; } /// /// A service for resolving a connection string from a name. /// [EntityFrameworkInternal] - public INamedConnectionStringResolver ConnectionStringResolver { get; } + public INamedConnectionStringResolver ConnectionStringResolver { get; [param: NotNull] init; } /// /// A service for creating instances. /// - public IRelationalTransactionFactory RelationalTransactionFactory { get; } + public IRelationalTransactionFactory RelationalTransactionFactory { get; [param: NotNull] init; } /// /// Contains the instance currently in use. /// - public ICurrentDbContext CurrentContext { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalConnectionDependencies With([NotNull] IDbContextOptions contextOptions) - => new RelationalConnectionDependencies( - contextOptions, - TransactionLogger, - ConnectionLogger, - ConnectionStringResolver, - RelationalTransactionFactory, - CurrentContext); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalConnectionDependencies With([NotNull] IDiagnosticsLogger connectionLogger) - => new RelationalConnectionDependencies( - ContextOptions, - TransactionLogger, - connectionLogger, - ConnectionStringResolver, - RelationalTransactionFactory, - CurrentContext); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalConnectionDependencies With([NotNull] IDiagnosticsLogger transactionLogger) - => new RelationalConnectionDependencies( - ContextOptions, - transactionLogger, - ConnectionLogger, - ConnectionStringResolver, - RelationalTransactionFactory, - CurrentContext); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - [EntityFrameworkInternal] - public RelationalConnectionDependencies With([NotNull] INamedConnectionStringResolver connectionStringResolver) - => new RelationalConnectionDependencies( - ContextOptions, - TransactionLogger, - ConnectionLogger, - connectionStringResolver, - RelationalTransactionFactory, - CurrentContext); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalConnectionDependencies With([NotNull] IRelationalTransactionFactory relationalTransactionFactory) - => new RelationalConnectionDependencies( - ContextOptions, - TransactionLogger, - ConnectionLogger, - ConnectionStringResolver, - relationalTransactionFactory, - CurrentContext); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalConnectionDependencies With([NotNull] ICurrentDbContext currentContext) - => new RelationalConnectionDependencies( - ContextOptions, - TransactionLogger, - ConnectionLogger, - ConnectionStringResolver, - RelationalTransactionFactory, - currentContext); + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs b/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs index 9b4f16f957d..bbf69cd5f50 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs @@ -34,7 +34,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalDatabaseCreatorDependencies + public sealed record RelationalDatabaseCreatorDependencies { /// /// @@ -97,199 +97,46 @@ public RelationalDatabaseCreatorDependencies( /// /// The model differ. /// - public IMigrationsModelDiffer ModelDiffer { get; } + public IMigrationsModelDiffer ModelDiffer { get; [param: NotNull] init; } /// /// The Migrations SQL generator. /// - public IMigrationsSqlGenerator MigrationsSqlGenerator { get; } + public IMigrationsSqlGenerator MigrationsSqlGenerator { get; [param: NotNull] init; } /// /// Gets the model for the context this creator is being used with. /// - public IModel Model { get; } + public IModel Model { get; [param: NotNull] init; } /// /// Gets the connection for the database. /// - public IRelationalConnection Connection { get; } + public IRelationalConnection Connection { get; [param: NotNull] init; } /// /// Gets the to be used. /// - public IMigrationCommandExecutor MigrationCommandExecutor { get; } + public IMigrationCommandExecutor MigrationCommandExecutor { get; [param: NotNull] init; } /// /// Gets the to be used. /// - public ISqlGenerationHelper SqlGenerationHelper { get; } + public ISqlGenerationHelper SqlGenerationHelper { get; [param: NotNull] init; } /// /// Gets the to be used. /// - public IExecutionStrategyFactory ExecutionStrategyFactory { get; } + public IExecutionStrategyFactory ExecutionStrategyFactory { get; [param: NotNull] init; } /// /// The command logger. /// - public IDiagnosticsLogger CommandLogger { get; } + public IDiagnosticsLogger CommandLogger { get; [param: NotNull] init; } /// /// Contains the currently in use. /// - public ICurrentDbContext CurrentContext { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] IModel model) - => new RelationalDatabaseCreatorDependencies( - model, - Connection, - ModelDiffer, - MigrationsSqlGenerator, - MigrationCommandExecutor, - SqlGenerationHelper, - ExecutionStrategyFactory, - CurrentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] IRelationalConnection connection) - => new RelationalDatabaseCreatorDependencies( - Model, - connection, - ModelDiffer, - MigrationsSqlGenerator, - MigrationCommandExecutor, - SqlGenerationHelper, - ExecutionStrategyFactory, - CurrentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] IMigrationsModelDiffer modelDiffer) - => new RelationalDatabaseCreatorDependencies( - Model, - Connection, - modelDiffer, - MigrationsSqlGenerator, - MigrationCommandExecutor, - SqlGenerationHelper, - ExecutionStrategyFactory, - CurrentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] IMigrationsSqlGenerator migrationsSqlGenerator) - => new RelationalDatabaseCreatorDependencies( - Model, - Connection, - ModelDiffer, - migrationsSqlGenerator, - MigrationCommandExecutor, - SqlGenerationHelper, - ExecutionStrategyFactory, - CurrentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] IMigrationCommandExecutor migrationCommandExecutor) - => new RelationalDatabaseCreatorDependencies( - Model, - Connection, - ModelDiffer, - MigrationsSqlGenerator, - migrationCommandExecutor, - SqlGenerationHelper, - ExecutionStrategyFactory, - CurrentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper) - => new RelationalDatabaseCreatorDependencies( - Model, - Connection, - ModelDiffer, - MigrationsSqlGenerator, - MigrationCommandExecutor, - sqlGenerationHelper, - ExecutionStrategyFactory, - CurrentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] IExecutionStrategyFactory executionStrategyFactory) - => new RelationalDatabaseCreatorDependencies( - Model, - Connection, - ModelDiffer, - MigrationsSqlGenerator, - MigrationCommandExecutor, - SqlGenerationHelper, - executionStrategyFactory, - CurrentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] ICurrentDbContext currentContext) - => new RelationalDatabaseCreatorDependencies( - Model, - Connection, - ModelDiffer, - MigrationsSqlGenerator, - MigrationCommandExecutor, - SqlGenerationHelper, - ExecutionStrategyFactory, - currentContext, - CommandLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalDatabaseCreatorDependencies With([NotNull] IDiagnosticsLogger commandLogger) - => new RelationalDatabaseCreatorDependencies( - Model, - Connection, - ModelDiffer, - MigrationsSqlGenerator, - MigrationCommandExecutor, - SqlGenerationHelper, - ExecutionStrategyFactory, - CurrentContext, - commandLogger); + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs b/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs index 2252f5449bc..e403a7c58b4 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// The implementation does not need to be thread-safe. /// /// - public sealed class RelationalDatabaseDependencies + public sealed record RelationalDatabaseDependencies { /// /// @@ -71,46 +71,16 @@ public RelationalDatabaseDependencies( /// /// The to be used. /// - public ICommandBatchPreparer BatchPreparer { get; } + public ICommandBatchPreparer BatchPreparer { get; [param: NotNull] init; } /// /// The to be used. /// - public IBatchExecutor BatchExecutor { get; } + public IBatchExecutor BatchExecutor { get; [param: NotNull] init; } /// /// The to be used. /// - public IRelationalConnection Connection { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// - /// A replacement for the current dependency of this type. - /// - /// A new parameter object with the given service replaced. - public RelationalDatabaseDependencies With([NotNull] ICommandBatchPreparer batchPreparer) - => new RelationalDatabaseDependencies(batchPreparer, BatchExecutor, Connection); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// - /// A replacement for the current dependency of this type. - /// - /// A new parameter object with the given service replaced. - public RelationalDatabaseDependencies With([NotNull] IBatchExecutor batchExecutor) - => new RelationalDatabaseDependencies(BatchPreparer, batchExecutor, Connection); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// - /// A replacement for the current dependency of this type. - /// - /// A new parameter object with the given service replaced. - public RelationalDatabaseDependencies With([NotNull] IRelationalConnection connection) - => new RelationalDatabaseDependencies(BatchPreparer, BatchExecutor, connection); + public IRelationalConnection Connection { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs index 25d9daa65b7..e2f3e51f33d 100644 --- a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class RelationalSqlGenerationHelperDependencies + public sealed record RelationalSqlGenerationHelperDependencies { /// /// diff --git a/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs b/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs index b0b340754e7..c48070bb52c 100644 --- a/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class RelationalTransactionFactoryDependencies + public sealed record RelationalTransactionFactoryDependencies { /// /// @@ -63,14 +63,6 @@ public RelationalTransactionFactoryDependencies([NotNull] ISqlGenerationHelper s /// /// Helpers for SQL generation. /// - public ISqlGenerationHelper SqlGenerationHelper { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalTransactionFactoryDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper) - => new RelationalTransactionFactoryDependencies(sqlGenerationHelper); + public ISqlGenerationHelper SqlGenerationHelper { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs index 580d6e82f04..eeb52f7e11c 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class RelationalTypeMappingSourceDependencies + public sealed record RelationalTypeMappingSourceDependencies { /// /// @@ -65,15 +65,6 @@ public RelationalTypeMappingSourceDependencies( /// /// Gets the plugins. /// - public IEnumerable Plugins { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalTypeMappingSourceDependencies With( - [NotNull] IEnumerable plugins) - => new RelationalTypeMappingSourceDependencies(plugins); + public IEnumerable Plugins { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs b/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs index 202da381ab2..cf5eeb522dd 100644 --- a/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class RelationalValueBufferFactoryDependencies + public sealed record RelationalValueBufferFactoryDependencies { /// /// @@ -73,27 +73,11 @@ public RelationalValueBufferFactoryDependencies( /// /// Gets the type mapping source. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// Gets core options. /// - public ICoreSingletonOptions CoreOptions { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalValueBufferFactoryDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new RelationalValueBufferFactoryDependencies(typeMappingSource, CoreOptions); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public RelationalValueBufferFactoryDependencies With([NotNull] ICoreSingletonOptions coreOptions) - => new RelationalValueBufferFactoryDependencies(TypeMappingSource, coreOptions); + public ICoreSingletonOptions CoreOptions { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs b/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs index e2ffb2b65e8..5024c01fefe 100644 --- a/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs +++ b/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Update.Internal /// The implementation does not need to be thread-safe. /// /// - public sealed class CommandBatchPreparerDependencies + public sealed record CommandBatchPreparerDependencies { /// /// @@ -85,7 +85,7 @@ public CommandBatchPreparerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IModificationCommandBatchFactory ModificationCommandBatchFactory { get; } + public IModificationCommandBatchFactory ModificationCommandBatchFactory { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -93,7 +93,7 @@ public CommandBatchPreparerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; } + public IParameterNameGeneratorFactory ParameterNameGeneratorFactory { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -101,7 +101,7 @@ public CommandBatchPreparerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IComparer ModificationCommandComparer { get; } + public IComparer ModificationCommandComparer { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -109,7 +109,7 @@ public CommandBatchPreparerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IKeyValueIndexFactorySource KeyValueIndexFactorySource { get; } + public IKeyValueIndexFactorySource KeyValueIndexFactorySource { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -117,7 +117,7 @@ public CommandBatchPreparerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public ILoggingOptions LoggingOptions { get; } + public ILoggingOptions LoggingOptions { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -125,7 +125,7 @@ public CommandBatchPreparerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDiagnosticsLogger UpdateLogger { get; } + public IDiagnosticsLogger UpdateLogger { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -133,111 +133,6 @@ public CommandBatchPreparerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDbContextOptions Options { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CommandBatchPreparerDependencies With([NotNull] IModificationCommandBatchFactory modificationCommandBatchFactory) - => new CommandBatchPreparerDependencies( - modificationCommandBatchFactory, - ParameterNameGeneratorFactory, - ModificationCommandComparer, - KeyValueIndexFactorySource, - LoggingOptions, - UpdateLogger, - Options); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CommandBatchPreparerDependencies With([NotNull] IParameterNameGeneratorFactory parameterNameGeneratorFactory) - => new CommandBatchPreparerDependencies( - ModificationCommandBatchFactory, - parameterNameGeneratorFactory, - ModificationCommandComparer, - KeyValueIndexFactorySource, - LoggingOptions, - UpdateLogger, - Options); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CommandBatchPreparerDependencies With([NotNull] IComparer modificationCommandComparer) - => new CommandBatchPreparerDependencies( - ModificationCommandBatchFactory, - ParameterNameGeneratorFactory, - modificationCommandComparer, - KeyValueIndexFactorySource, - LoggingOptions, - UpdateLogger, - Options); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CommandBatchPreparerDependencies With([NotNull] IKeyValueIndexFactorySource keyValueIndexFactorySource) - => new CommandBatchPreparerDependencies( - ModificationCommandBatchFactory, - ParameterNameGeneratorFactory, - ModificationCommandComparer, - keyValueIndexFactorySource, - LoggingOptions, - UpdateLogger, - Options); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CommandBatchPreparerDependencies With([NotNull] ILoggingOptions loggingOptions) - => new CommandBatchPreparerDependencies( - ModificationCommandBatchFactory, - ParameterNameGeneratorFactory, - ModificationCommandComparer, - KeyValueIndexFactorySource, - loggingOptions, - UpdateLogger, - Options); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CommandBatchPreparerDependencies With([NotNull] IDiagnosticsLogger updateLogger) - => new CommandBatchPreparerDependencies( - ModificationCommandBatchFactory, - ParameterNameGeneratorFactory, - ModificationCommandComparer, - KeyValueIndexFactorySource, - LoggingOptions, - updateLogger, - Options); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CommandBatchPreparerDependencies With([NotNull] IDbContextOptions options) - => new CommandBatchPreparerDependencies( - ModificationCommandBatchFactory, - ParameterNameGeneratorFactory, - ModificationCommandComparer, - KeyValueIndexFactorySource, - LoggingOptions, - UpdateLogger, - options); + public IDbContextOptions Options { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs b/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs index 7dc1dec4c59..3a1786ef5a9 100644 --- a/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs +++ b/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Update /// The implementation does not need to be thread-safe. /// /// - public sealed class ModificationCommandBatchFactoryDependencies + public sealed record ModificationCommandBatchFactoryDependencies { /// /// @@ -80,115 +80,31 @@ public ModificationCommandBatchFactoryDependencies( /// /// A logger. /// - public IDiagnosticsLogger Logger { get; } + public IDiagnosticsLogger Logger { get; [param: NotNull] init; } /// /// The command builder factory. /// - public IRelationalCommandBuilderFactory CommandBuilderFactory { get; } + public IRelationalCommandBuilderFactory CommandBuilderFactory { get; [param: NotNull] init; } /// /// The SQL generator helper. /// - public ISqlGenerationHelper SqlGenerationHelper { get; } + public ISqlGenerationHelper SqlGenerationHelper { get; [param: NotNull] init; } /// /// The update SQL generator. /// - public IUpdateSqlGenerator UpdateSqlGenerator { get; } + public IUpdateSqlGenerator UpdateSqlGenerator { get; [param: NotNull] init; } /// /// The value buffer factory. /// - public IRelationalValueBufferFactoryFactory ValueBufferFactoryFactory { get; } + public IRelationalValueBufferFactoryFactory ValueBufferFactoryFactory { get; [param: NotNull] init; } /// /// Contains the currently in use. /// - public ICurrentDbContext CurrentContext { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModificationCommandBatchFactoryDependencies With([NotNull] IDiagnosticsLogger logger) - => new ModificationCommandBatchFactoryDependencies( - CommandBuilderFactory, - SqlGenerationHelper, - UpdateSqlGenerator, - ValueBufferFactoryFactory, - CurrentContext, - logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModificationCommandBatchFactoryDependencies With([NotNull] IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) - => new ModificationCommandBatchFactoryDependencies( - CommandBuilderFactory, - SqlGenerationHelper, - UpdateSqlGenerator, - valueBufferFactoryFactory, - CurrentContext, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModificationCommandBatchFactoryDependencies With([NotNull] IRelationalCommandBuilderFactory commandBuilderFactory) - => new ModificationCommandBatchFactoryDependencies( - commandBuilderFactory, - SqlGenerationHelper, - UpdateSqlGenerator, - ValueBufferFactoryFactory, - CurrentContext, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModificationCommandBatchFactoryDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper) - => new ModificationCommandBatchFactoryDependencies( - CommandBuilderFactory, - sqlGenerationHelper, - UpdateSqlGenerator, - ValueBufferFactoryFactory, - CurrentContext, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModificationCommandBatchFactoryDependencies With([NotNull] IUpdateSqlGenerator updateSqlGenerator) - => new ModificationCommandBatchFactoryDependencies( - CommandBuilderFactory, - SqlGenerationHelper, - updateSqlGenerator, - ValueBufferFactoryFactory, - CurrentContext, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModificationCommandBatchFactoryDependencies With([NotNull] ICurrentDbContext currentContext) - => new ModificationCommandBatchFactoryDependencies( - CommandBuilderFactory, - SqlGenerationHelper, - UpdateSqlGenerator, - ValueBufferFactoryFactory, - currentContext, - Logger); + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } } } diff --git a/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs b/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs index 25d73494374..17f99da5a85 100644 --- a/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Update /// This service cannot depend on services registered as . /// /// - public sealed class UpdateSqlGeneratorDependencies + public sealed record UpdateSqlGeneratorDependencies { /// /// @@ -74,31 +74,11 @@ public UpdateSqlGeneratorDependencies( /// /// Helpers for generating update SQL. /// - public ISqlGenerationHelper SqlGenerationHelper { get; } + public ISqlGenerationHelper SqlGenerationHelper { get; [param: NotNull] init; } /// /// The type mapping source. /// - public IRelationalTypeMappingSource TypeMappingSource { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public UpdateSqlGeneratorDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper) - => new UpdateSqlGeneratorDependencies( - sqlGenerationHelper, - TypeMappingSource); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public UpdateSqlGeneratorDependencies With([NotNull] IRelationalTypeMappingSource typeMappingSource) - => new UpdateSqlGeneratorDependencies( - SqlGenerationHelper, - typeMappingSource); + public IRelationalTypeMappingSource TypeMappingSource { get; [param: NotNull] init; } } } diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs index 2114f657796..44e6a2b4a4a 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs @@ -89,7 +89,7 @@ public virtual ISqlServerConnection CreateMasterConnection() b => b.CommandTimeout(CommandTimeout ?? DefaultMasterConnectionCommandTimeout)) .Options; - return new SqlServerConnection(Dependencies.With(contextOptions)); + return new SqlServerConnection(Dependencies with { ContextOptions = contextOptions }); } /// diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs index a3768215a79..905ddc2fab1 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs @@ -37,8 +37,6 @@ public SqlServerTransaction( { } - // SQL Server doesn't support releasing savepoints. Override to do nothing. - /// public override bool SupportsSavepoints { diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs index 1d32e86e7fc..586af92e4e3 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs @@ -98,7 +98,7 @@ public virtual ISqliteRelationalConnection CreateReadOnlyConnection() var contextOptions = new DbContextOptionsBuilder().UseSqlite(connectionStringBuilder.ToString()).Options; - return new SqliteRelationalConnection(Dependencies.With(contextOptions), _rawSqlCommandBuilder, _logger); + return new SqliteRelationalConnection(Dependencies with { ContextOptions = contextOptions }, _rawSqlCommandBuilder, _logger); } private void InitializeDbConnection(DbConnection connection) diff --git a/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs b/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs index fcc6cd6fd5b..038f584e267 100644 --- a/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs +++ b/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs @@ -35,7 +35,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// The implementation does not need to be thread-safe. /// /// - public sealed class StateManagerDependencies + public sealed record StateManagerDependencies { /// /// @@ -103,7 +103,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IInternalEntityEntryFactory InternalEntityEntryFactory { get; } + public IInternalEntityEntryFactory InternalEntityEntryFactory { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -111,7 +111,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IInternalEntityEntrySubscriber InternalEntityEntrySubscriber { get; } + public IInternalEntityEntrySubscriber InternalEntityEntrySubscriber { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -119,7 +119,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IInternalEntityEntryNotifier InternalEntityEntryNotifier { get; } + public IInternalEntityEntryNotifier InternalEntityEntryNotifier { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -127,7 +127,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IValueGenerationManager ValueGenerationManager { get; } + public IValueGenerationManager ValueGenerationManager { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -135,7 +135,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IModel Model { get; } + public IModel Model { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -143,7 +143,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDatabase Database { get; } + public IDatabase Database { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -151,7 +151,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IConcurrencyDetector ConcurrencyDetector { get; } + public IConcurrencyDetector ConcurrencyDetector { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -159,7 +159,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public ICurrentDbContext CurrentContext { get; } + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -168,7 +168,7 @@ public StateManagerDependencies( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public IDbSetSource SetSource { get; } + public IDbSetSource SetSource { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -177,7 +177,7 @@ public StateManagerDependencies( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public IEntityFinderSource EntityFinderSource { get; } + public IEntityFinderSource EntityFinderSource { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -185,7 +185,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IEntityMaterializerSource EntityMaterializerSource { get; } + public IEntityMaterializerSource EntityMaterializerSource { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -193,7 +193,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IExecutionStrategyFactory ExecutionStrategyFactory { get; } + public IExecutionStrategyFactory ExecutionStrategyFactory { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -201,7 +201,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public ILoggingOptions LoggingOptions { get; } + public ILoggingOptions LoggingOptions { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -209,7 +209,7 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDiagnosticsLogger UpdateLogger { get; } + public IDiagnosticsLogger UpdateLogger { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -217,353 +217,6 @@ public StateManagerDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDiagnosticsLogger ChangeTrackingLogger { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IInternalEntityEntryFactory internalEntityEntryFactory) - => new StateManagerDependencies( - internalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IInternalEntityEntrySubscriber internalEntityEntrySubscriber) - => new StateManagerDependencies( - InternalEntityEntryFactory, - internalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IInternalEntityEntryNotifier internalEntityEntryNotifier) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - internalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IValueGenerationManager valueGenerationManager) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - valueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IModel model) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IDatabase database) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IConcurrencyDetector concurrencyDetector) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - concurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] ICurrentDbContext currentContext) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - currentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - [EntityFrameworkInternal] - public StateManagerDependencies With([NotNull] IEntityFinderSource entityFinderSource) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - entityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - [EntityFrameworkInternal] - public StateManagerDependencies With([NotNull] IDbSetSource setSource) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - setSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IEntityMaterializerSource entityMaterializerSource) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - entityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IExecutionStrategyFactory executionStrategyFactory) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - executionStrategyFactory, - LoggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] ILoggingOptions loggingOptions) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - loggingOptions, - UpdateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IDiagnosticsLogger updateLogger) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - updateLogger, - ChangeTrackingLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public StateManagerDependencies With([NotNull] IDiagnosticsLogger changeTrackingLogger) - => new StateManagerDependencies( - InternalEntityEntryFactory, - InternalEntityEntrySubscriber, - InternalEntityEntryNotifier, - ValueGenerationManager, - Model, - Database, - ConcurrencyDetector, - CurrentContext, - EntityFinderSource, - SetSource, - EntityMaterializerSource, - ExecutionStrategyFactory, - LoggingOptions, - UpdateLogger, - changeTrackingLogger); + public IDiagnosticsLogger ChangeTrackingLogger { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs b/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs index 3df41cb9513..ede12b187b4 100644 --- a/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs +++ b/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs @@ -28,7 +28,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// This service cannot depend on services registered as . /// /// - public sealed class ModelCacheKeyFactoryDependencies + public sealed record ModelCacheKeyFactoryDependencies { /// /// diff --git a/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs b/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs index f8e86beaf00..b3a3a90d2a6 100644 --- a/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs +++ b/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs @@ -30,7 +30,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// This service cannot depend on services registered as . /// /// - public sealed class ModelCustomizerDependencies + public sealed record ModelCustomizerDependencies { /// /// @@ -63,14 +63,6 @@ public ModelCustomizerDependencies([NotNull] IDbSetFinder setFinder) /// Gets the that will locate the properties /// on the derived context. /// - public IDbSetFinder SetFinder { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelCustomizerDependencies With([NotNull] IDbSetFinder setFinder) - => new ModelCustomizerDependencies(setFinder); + public IDbSetFinder SetFinder { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Infrastructure/ModelDependencies.cs b/src/EFCore/Infrastructure/ModelDependencies.cs index a8aa7f4810d..ce7db84254f 100644 --- a/src/EFCore/Infrastructure/ModelDependencies.cs +++ b/src/EFCore/Infrastructure/ModelDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// The implementation does not need to be thread-safe. /// /// - public sealed class ModelDependencies + public sealed record ModelDependencies { /// /// @@ -65,14 +65,6 @@ public ModelDependencies( /// /// Gets the logger. /// - public IDiagnosticsLogger Logger { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelDependencies With([NotNull] IDiagnosticsLogger logger) - => new ModelDependencies(logger); + public IDiagnosticsLogger Logger { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Infrastructure/ModelSourceDependencies.cs b/src/EFCore/Infrastructure/ModelSourceDependencies.cs index 35190f11d81..ef2fd4c83c2 100644 --- a/src/EFCore/Infrastructure/ModelSourceDependencies.cs +++ b/src/EFCore/Infrastructure/ModelSourceDependencies.cs @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// This service cannot depend on services registered as . /// /// - public sealed class ModelSourceDependencies + public sealed record ModelSourceDependencies { /// /// @@ -71,41 +71,17 @@ public ModelSourceDependencies( /// Gets the that will perform additional configuration of the model /// in addition to what is discovered by convention. /// - public IModelCustomizer ModelCustomizer { get; } + public IModelCustomizer ModelCustomizer { get; [param: NotNull] init; } /// /// Gets the that will create keys used to store and lookup models /// the model cache. /// - public IModelCacheKeyFactory ModelCacheKeyFactory { get; } + public IModelCacheKeyFactory ModelCacheKeyFactory { get; [param: NotNull] init; } /// /// Gets the that will be used to cache models. /// - public IMemoryCache MemoryCache { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelSourceDependencies With([NotNull] IModelCustomizer modelCustomizer) - => new ModelSourceDependencies(modelCustomizer, ModelCacheKeyFactory, MemoryCache); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelSourceDependencies With([NotNull] IModelCacheKeyFactory modelCacheKeyFactory) - => new ModelSourceDependencies(ModelCustomizer, modelCacheKeyFactory, MemoryCache); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelSourceDependencies With([NotNull] IMemoryCache memoryCache) - => new ModelSourceDependencies(ModelCustomizer, ModelCacheKeyFactory, memoryCache); + public IMemoryCache MemoryCache { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Infrastructure/ModelValidatorDependencies.cs b/src/EFCore/Infrastructure/ModelValidatorDependencies.cs index 6d470eba83a..c9d36bdf085 100644 --- a/src/EFCore/Infrastructure/ModelValidatorDependencies.cs +++ b/src/EFCore/Infrastructure/ModelValidatorDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// This service cannot depend on services registered as . /// /// - public sealed class ModelValidatorDependencies + public sealed record ModelValidatorDependencies { /// /// @@ -72,29 +72,12 @@ public ModelValidatorDependencies( /// /// The type mapper. /// - public ITypeMappingSource TypeMappingSource { get; } + public ITypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// The member classifier. /// [EntityFrameworkInternal] - public IMemberClassifier MemberClassifier { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelValidatorDependencies With([NotNull] ITypeMappingSource typeMappingSource) - => new ModelValidatorDependencies(typeMappingSource, MemberClassifier); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - [EntityFrameworkInternal] - public ModelValidatorDependencies With([NotNull] IMemberClassifier memberClassifier) - => new ModelValidatorDependencies(TypeMappingSource, memberClassifier); + public IMemberClassifier MemberClassifier { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Internal/DbContextDependencies.cs b/src/EFCore/Internal/DbContextDependencies.cs index 8e11420c41d..69700f23446 100644 --- a/src/EFCore/Internal/DbContextDependencies.cs +++ b/src/EFCore/Internal/DbContextDependencies.cs @@ -28,7 +28,7 @@ namespace Microsoft.EntityFrameworkCore.Internal /// The implementation does not need to be thread-safe. /// /// - public sealed class DbContextDependencies : IDbContextDependencies + public sealed record DbContextDependencies : IDbContextDependencies { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -65,7 +65,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IModel Model { get; } + public IModel Model { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -73,7 +73,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDbSetSource SetSource { get; } + public IDbSetSource SetSource { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -81,7 +81,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IEntityFinderFactory EntityFinderFactory { get; } + public IEntityFinderFactory EntityFinderFactory { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -89,7 +89,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IAsyncQueryProvider QueryProvider { get; } + public IAsyncQueryProvider QueryProvider { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -97,7 +97,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IStateManager StateManager { get; } + public IStateManager StateManager { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -105,7 +105,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IChangeDetector ChangeDetector { get; } + public IChangeDetector ChangeDetector { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -113,7 +113,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IEntityGraphAttacher EntityGraphAttacher { get; } + public IEntityGraphAttacher EntityGraphAttacher { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -121,7 +121,7 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDiagnosticsLogger UpdateLogger { get; } + public IDiagnosticsLogger UpdateLogger { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -129,6 +129,6 @@ public DbContextDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IDiagnosticsLogger InfrastructureLogger { get; } + public IDiagnosticsLogger InfrastructureLogger { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Internal/ModelCreationDependencies.cs b/src/EFCore/Internal/ModelCreationDependencies.cs index e024a9a946e..1b98d5880dd 100644 --- a/src/EFCore/Internal/ModelCreationDependencies.cs +++ b/src/EFCore/Internal/ModelCreationDependencies.cs @@ -23,7 +23,7 @@ namespace Microsoft.EntityFrameworkCore.Internal /// The implementation does not need to be thread-safe. /// /// - public sealed class ModelCreationDependencies : IModelCreationDependencies + public sealed record ModelCreationDependencies : IModelCreationDependencies { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -51,7 +51,7 @@ public ModelCreationDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IModelSource ModelSource { get; } + public IModelSource ModelSource { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -59,7 +59,7 @@ public ModelCreationDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public IConventionSetBuilder ConventionSetBuilder { get; } + public IConventionSetBuilder ConventionSetBuilder { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -67,30 +67,6 @@ public ModelCreationDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public ModelDependencies ModelDependencies { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelCreationDependencies With([NotNull] IModelSource modelSource) - => new ModelCreationDependencies(modelSource, ConventionSetBuilder, ModelDependencies); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelCreationDependencies With([NotNull] IConventionSetBuilder conventionSetBuilder) - => new ModelCreationDependencies(ModelSource, conventionSetBuilder, ModelDependencies); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ModelCreationDependencies With([NotNull] ModelDependencies modelDependencies) - => new ModelCreationDependencies(ModelSource, ConventionSetBuilder, modelDependencies); + public ModelDependencies ModelDependencies { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs index 05069b18aab..d015fcde550 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs @@ -41,7 +41,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure /// The implementation does not need to be thread-safe. /// /// - public sealed class ProviderConventionSetBuilderDependencies + public sealed record ProviderConventionSetBuilderDependencies { private readonly ICurrentDbContext _currentContext; @@ -105,38 +105,38 @@ public ProviderConventionSetBuilderDependencies( /// /// The type mapping source. /// - public ITypeMappingSource TypeMappingSource { get; } + public ITypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// The parameter binding factories. /// - public IParameterBindingFactories ParameterBindingFactories { get; } + public IParameterBindingFactories ParameterBindingFactories { get; [param: NotNull] init; } /// /// The member classifier. /// [EntityFrameworkInternal] - public IMemberClassifier MemberClassifier { get; } + public IMemberClassifier MemberClassifier { get; [param: NotNull] init; } /// /// The constructor binding factory. /// - public IConstructorBindingFactory ConstructorBindingFactory { get; } + public IConstructorBindingFactory ConstructorBindingFactory { get; [param: NotNull] init; } /// /// The model logger. /// - public IDiagnosticsLogger Logger { get; } + public IDiagnosticsLogger Logger { get; [param: NotNull] init; } /// /// The model validation logger. /// - public IDiagnosticsLogger ValidationLogger { get; } + public IDiagnosticsLogger ValidationLogger { get; [param: NotNull] init; } /// /// The set finder. /// - public IDbSetFinder SetFinder { get; } + public IDbSetFinder SetFinder { get; [param: NotNull] init; } /// /// The current context instance. @@ -147,79 +147,7 @@ public Type ContextType /// /// The model validator. /// - public IModelValidator ModelValidator { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With([NotNull] ITypeMappingSource typeMappingSource) - => new ProviderConventionSetBuilderDependencies( - typeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, MemberClassifier, Logger, ValidationLogger, - SetFinder, _currentContext, ModelValidator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With([NotNull] IConstructorBindingFactory constructorBindingFactory) - => new ProviderConventionSetBuilderDependencies( - TypeMappingSource, constructorBindingFactory, ParameterBindingFactories, MemberClassifier, Logger, ValidationLogger, - SetFinder, _currentContext, ModelValidator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With([NotNull] IDiagnosticsLogger logger) - => new ProviderConventionSetBuilderDependencies( - TypeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, MemberClassifier, logger, ValidationLogger, - SetFinder, _currentContext, ModelValidator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With( - [NotNull] IDiagnosticsLogger validationLogger) - => new ProviderConventionSetBuilderDependencies( - TypeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, MemberClassifier, Logger, validationLogger, - SetFinder, _currentContext, ModelValidator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With([NotNull] IParameterBindingFactories parameterBindingFactories) - => new ProviderConventionSetBuilderDependencies( - TypeMappingSource, ConstructorBindingFactory, parameterBindingFactories, MemberClassifier, Logger, ValidationLogger, - SetFinder, _currentContext, ModelValidator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - [EntityFrameworkInternal] - public ProviderConventionSetBuilderDependencies With([NotNull] IMemberClassifier memberClassifier) - => new ProviderConventionSetBuilderDependencies( - TypeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, memberClassifier, Logger, ValidationLogger, - SetFinder, _currentContext, ModelValidator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With([NotNull] IDbSetFinder setFinder) - => new ProviderConventionSetBuilderDependencies( - TypeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, MemberClassifier, Logger, ValidationLogger, - setFinder, _currentContext, ModelValidator); + public IModelValidator ModelValidator { get; [param: NotNull] init; } /// /// Clones this dependency parameter object with one service replaced. @@ -230,15 +158,5 @@ public ProviderConventionSetBuilderDependencies With([NotNull] ICurrentDbContext => new ProviderConventionSetBuilderDependencies( TypeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, MemberClassifier, Logger, ValidationLogger, SetFinder, currentContext, ModelValidator); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With([NotNull] IModelValidator validator) - => new ProviderConventionSetBuilderDependencies( - TypeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, MemberClassifier, Logger, ValidationLogger, - SetFinder, _currentContext, validator); } } diff --git a/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs b/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs index 76a5a2ccd78..dd5153ab396 100644 --- a/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs +++ b/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// This service cannot depend on services registered as . /// /// - public sealed class LazyLoaderParameterBindingFactoryDependencies + public sealed record LazyLoaderParameterBindingFactoryDependencies { /// /// diff --git a/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs b/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs index 38515f511d2..971003d6a76 100644 --- a/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs +++ b/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs @@ -35,10 +35,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// The implementation does not need to be thread-safe. /// /// - public sealed class CompiledQueryCacheKeyGeneratorDependencies + public sealed record CompiledQueryCacheKeyGeneratorDependencies { - private readonly IExecutionStrategyFactory _executionStrategyFactory; - /// /// /// Creates the service dependencies parameter object for a . @@ -74,47 +72,22 @@ public CompiledQueryCacheKeyGeneratorDependencies( Model = model; CurrentContext = currentContext; - _executionStrategyFactory = executionStrategyFactory; IsRetryingExecutionStrategy = executionStrategyFactory.Create().RetriesOnFailure; } /// /// The model that queries will be written against. /// - public IModel Model { get; } + public IModel Model { get; [param: NotNull] init; } /// /// The context that queries will be executed for. /// - public ICurrentDbContext CurrentContext { get; } + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } /// /// Whether the configured execution strategy can retry. /// - public bool IsRetryingExecutionStrategy { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CompiledQueryCacheKeyGeneratorDependencies With([NotNull] IModel model) - => new CompiledQueryCacheKeyGeneratorDependencies(model, CurrentContext, _executionStrategyFactory); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CompiledQueryCacheKeyGeneratorDependencies With([NotNull] ICurrentDbContext currentContext) - => new CompiledQueryCacheKeyGeneratorDependencies(Model, currentContext, _executionStrategyFactory); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public CompiledQueryCacheKeyGeneratorDependencies With([NotNull] IExecutionStrategyFactory executionStrategyFactory) - => new CompiledQueryCacheKeyGeneratorDependencies(Model, CurrentContext, executionStrategyFactory); + public bool IsRetryingExecutionStrategy { get; init; } } } diff --git a/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs b/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs index f7e8d46ccd4..b2e697df89a 100644 --- a/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs +++ b/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class EvaluatableExpressionFilterDependencies + public sealed record EvaluatableExpressionFilterDependencies { /// /// @@ -65,14 +65,6 @@ public EvaluatableExpressionFilterDependencies([NotNull] IEnumerable /// Gets the plugins. /// - public IEnumerable Plugins { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public EvaluatableExpressionFilterDependencies With([NotNull] IEnumerable plugins) - => new EvaluatableExpressionFilterDependencies(plugins); + public IEnumerable Plugins { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Query/Internal/EntityMaterializerSourceDependencies.cs b/src/EFCore/Query/Internal/EntityMaterializerSourceDependencies.cs index d0c23f82398..a13152083a6 100644 --- a/src/EFCore/Query/Internal/EntityMaterializerSourceDependencies.cs +++ b/src/EFCore/Query/Internal/EntityMaterializerSourceDependencies.cs @@ -30,7 +30,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// This service cannot depend on services registered as . /// /// - public sealed class EntityMaterializerSourceDependencies + public sealed record EntityMaterializerSourceDependencies { /// /// diff --git a/src/EFCore/Query/QueryCompilationContextDependencies.cs b/src/EFCore/Query/QueryCompilationContextDependencies.cs index a5654034986..014a7721e08 100644 --- a/src/EFCore/Query/QueryCompilationContextDependencies.cs +++ b/src/EFCore/Query/QueryCompilationContextDependencies.cs @@ -37,9 +37,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// The implementation does not need to be thread-safe. /// /// - public sealed class QueryCompilationContextDependencies + public sealed record QueryCompilationContextDependencies { - private readonly IExecutionStrategyFactory _executionStrategyFactory; private readonly ICurrentDbContext _currentContext; /// @@ -89,7 +88,6 @@ public QueryCompilationContextDependencies( QueryableMethodTranslatingExpressionVisitorFactory = queryableMethodTranslatingExpressionVisitorFactory; QueryTranslationPostprocessorFactory = queryTranslationPostprocessorFactory; ShapedQueryCompilingExpressionVisitorFactory = shapedQueryCompilingExpressionVisitorFactory; - _executionStrategyFactory = executionStrategyFactory; IsRetryingExecutionStrategy = executionStrategyFactory.Create().RetriesOnFailure; ContextOptions = contextOptions; Logger = logger; @@ -110,197 +108,45 @@ public QueryTrackingBehavior QueryTrackingBehavior /// /// The model. /// - public IModel Model { get; } + public IModel Model { get; [param: NotNull] init; } /// /// The query optimizer factory. /// - public IQueryTranslationPreprocessorFactory QueryTranslationPreprocessorFactory { get; } + public IQueryTranslationPreprocessorFactory QueryTranslationPreprocessorFactory { get; [param: NotNull] init; } /// /// The queryable method-translating expression visitor factory. /// - public IQueryableMethodTranslatingExpressionVisitorFactory QueryableMethodTranslatingExpressionVisitorFactory { get; } + public IQueryableMethodTranslatingExpressionVisitorFactory QueryableMethodTranslatingExpressionVisitorFactory + { + get; + [param: NotNull] init; + } /// /// The shaped-query optimizer factory /// - public IQueryTranslationPostprocessorFactory QueryTranslationPostprocessorFactory { get; } + public IQueryTranslationPostprocessorFactory QueryTranslationPostprocessorFactory { get; [param: NotNull] init; } /// /// The shaped-query compiling expression visitor factory. /// - public IShapedQueryCompilingExpressionVisitorFactory ShapedQueryCompilingExpressionVisitorFactory { get; } + public IShapedQueryCompilingExpressionVisitorFactory ShapedQueryCompilingExpressionVisitorFactory { get; [param: NotNull] init; } /// /// Whether the configured execution strategy can retry. /// - public bool IsRetryingExecutionStrategy { get; } + public bool IsRetryingExecutionStrategy { get; init; } /// /// The context options. /// - public IDbContextOptions ContextOptions { get; } + public IDbContextOptions ContextOptions { get; [param: NotNull] init; } /// /// The logger. /// - public IDiagnosticsLogger Logger { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With([NotNull] IModel model) - => new QueryCompilationContextDependencies( - model, - QueryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - _currentContext, - ContextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With([NotNull] IQueryTranslationPreprocessorFactory queryTranslationPreprocessorFactory) - => new QueryCompilationContextDependencies( - Model, - queryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - _currentContext, - ContextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With( - [NotNull] IQueryableMethodTranslatingExpressionVisitorFactory queryableMethodTranslatingExpressionVisitorFactory) - => new QueryCompilationContextDependencies( - Model, - QueryTranslationPreprocessorFactory, - queryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - _currentContext, - ContextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With( - [NotNull] IQueryTranslationPostprocessorFactory queryTranslationPostprocessorFactory) - => new QueryCompilationContextDependencies( - Model, - QueryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - queryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - _currentContext, - ContextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With( - [NotNull] IShapedQueryCompilingExpressionVisitorFactory shapedQueryCompilingExpressionVisitorFactory) - => new QueryCompilationContextDependencies( - Model, - QueryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - shapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - _currentContext, - ContextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With([NotNull] IExecutionStrategyFactory executionStrategyFactory) - => new QueryCompilationContextDependencies( - Model, - QueryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - executionStrategyFactory, - _currentContext, - ContextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With([NotNull] ICurrentDbContext currentContext) - => new QueryCompilationContextDependencies( - Model, - QueryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - currentContext, - ContextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With([NotNull] IDbContextOptions contextOptions) - => new QueryCompilationContextDependencies( - Model, - QueryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - _currentContext, - contextOptions, - Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With([NotNull] IDiagnosticsLogger logger) - => new QueryCompilationContextDependencies( - Model, - QueryTranslationPreprocessorFactory, - QueryableMethodTranslatingExpressionVisitorFactory, - QueryTranslationPostprocessorFactory, - ShapedQueryCompilingExpressionVisitorFactory, - _executionStrategyFactory, - _currentContext, - ContextOptions, - logger); + public IDiagnosticsLogger Logger { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Query/QueryContextDependencies.cs b/src/EFCore/Query/QueryContextDependencies.cs index 9181d6c5ab4..240b26e003f 100644 --- a/src/EFCore/Query/QueryContextDependencies.cs +++ b/src/EFCore/Query/QueryContextDependencies.cs @@ -39,7 +39,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// The implementation does not need to be thread-safe. /// /// - public sealed class QueryContextDependencies + public sealed record QueryContextDependencies { /// /// @@ -84,7 +84,7 @@ public QueryContextDependencies( /// /// The cache being used to store value generator instances. /// - public ICurrentDbContext CurrentContext { get; } + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -106,61 +106,21 @@ public IQueryProvider QueryProvider /// /// The execution strategy. /// - public IExecutionStrategyFactory ExecutionStrategyFactory { get; } + public IExecutionStrategyFactory ExecutionStrategyFactory { get; [param: NotNull] init; } /// /// Gets the concurrency detector. /// - public IConcurrencyDetector ConcurrencyDetector { get; } + public IConcurrencyDetector ConcurrencyDetector { get; [param: NotNull] init; } /// /// The command logger. /// - public IDiagnosticsLogger CommandLogger { get; } + public IDiagnosticsLogger CommandLogger { get; [param: NotNull] init; } /// /// A query logger. /// - public IDiagnosticsLogger QueryLogger { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryContextDependencies With([NotNull] ICurrentDbContext currentContext) - => new QueryContextDependencies(currentContext, ExecutionStrategyFactory, ConcurrencyDetector, CommandLogger, QueryLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryContextDependencies With([NotNull] IExecutionStrategyFactory executionStrategyFactor) - => new QueryContextDependencies(CurrentContext, executionStrategyFactor, ConcurrencyDetector, CommandLogger, QueryLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryContextDependencies With([NotNull] IConcurrencyDetector concurrencyDetector) - => new QueryContextDependencies(CurrentContext, ExecutionStrategyFactory, concurrencyDetector, CommandLogger, QueryLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryContextDependencies With([NotNull] IDiagnosticsLogger commandLogger) - => new QueryContextDependencies(CurrentContext, ExecutionStrategyFactory, ConcurrencyDetector, commandLogger, QueryLogger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryContextDependencies With([NotNull] IDiagnosticsLogger queryLogger) - => new QueryContextDependencies(CurrentContext, ExecutionStrategyFactory, ConcurrencyDetector, CommandLogger, queryLogger); + public IDiagnosticsLogger QueryLogger { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs b/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs index fa7d75b264b..f537562925e 100644 --- a/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs +++ b/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs @@ -30,7 +30,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class QueryTranslationPostprocessorDependencies + public sealed record QueryTranslationPostprocessorDependencies { /// /// diff --git a/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs b/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs index 55f071b1054..0c546dd7e39 100644 --- a/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs +++ b/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class QueryTranslationPreprocessorDependencies + public sealed record QueryTranslationPreprocessorDependencies { /// /// @@ -65,14 +65,6 @@ public QueryTranslationPreprocessorDependencies( /// /// Evaluatable expression filter. /// - public IEvaluatableExpressionFilter EvaluatableExpressionFilter { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public QueryTranslationPreprocessorDependencies With([NotNull] IEvaluatableExpressionFilter evaluatableExpressionFilter) - => new QueryTranslationPreprocessorDependencies(evaluatableExpressionFilter); + public IEvaluatableExpressionFilter EvaluatableExpressionFilter { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs index 8cc4a416dca..3c7140cf1c2 100644 --- a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs @@ -30,7 +30,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class QueryableMethodTranslatingExpressionVisitorDependencies + public sealed record QueryableMethodTranslatingExpressionVisitorDependencies { /// /// diff --git a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitorDependencies.cs b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitorDependencies.cs index 1217614aeda..1a862445d79 100644 --- a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitorDependencies.cs +++ b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitorDependencies.cs @@ -35,7 +35,7 @@ namespace Microsoft.EntityFrameworkCore.Query /// This service cannot depend on services registered as . /// /// - public sealed class ShapedQueryCompilingExpressionVisitorDependencies + public sealed record ShapedQueryCompilingExpressionVisitorDependencies { /// /// @@ -74,40 +74,16 @@ public ShapedQueryCompilingExpressionVisitorDependencies( /// /// The materializer source. /// - public IEntityMaterializerSource EntityMaterializerSource { get; } + public IEntityMaterializerSource EntityMaterializerSource { get; [param: NotNull] init; } /// /// The type mapping source. /// - public ITypeMappingSource TypeMappingSource { get; } + public ITypeMappingSource TypeMappingSource { get; [param: NotNull] init; } /// /// The memory cache. /// - public IMemoryCache MemoryCache { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ShapedQueryCompilingExpressionVisitorDependencies With([NotNull] IEntityMaterializerSource entityMaterializerSource) - => new ShapedQueryCompilingExpressionVisitorDependencies(entityMaterializerSource, TypeMappingSource, MemoryCache); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ShapedQueryCompilingExpressionVisitorDependencies With([NotNull] ITypeMappingSource typeMappingSource) - => new ShapedQueryCompilingExpressionVisitorDependencies(EntityMaterializerSource, typeMappingSource, MemoryCache); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ShapedQueryCompilingExpressionVisitorDependencies With([NotNull] IMemoryCache memoryCache) - => new ShapedQueryCompilingExpressionVisitorDependencies(EntityMaterializerSource, TypeMappingSource, memoryCache); + public IMemoryCache MemoryCache { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Storage/DatabaseDependencies.cs b/src/EFCore/Storage/DatabaseDependencies.cs index 28d45a39a00..d7f1094756a 100644 --- a/src/EFCore/Storage/DatabaseDependencies.cs +++ b/src/EFCore/Storage/DatabaseDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// The implementation does not need to be thread-safe. /// /// - public sealed class DatabaseDependencies + public sealed record DatabaseDependencies { /// /// @@ -69,31 +69,11 @@ public DatabaseDependencies( /// /// Factory for compilation contexts to process LINQ queries. /// - public IQueryCompilationContextFactory QueryCompilationContextFactory { get; } + public IQueryCompilationContextFactory QueryCompilationContextFactory { get; [param: NotNull] init; } /// /// Factory for creating model data tracker. /// - public IUpdateAdapterFactory UpdateAdapterFactory { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// - /// A replacement for the current dependency of this type. - /// - /// A new parameter object with the given service replaced. - public DatabaseDependencies With([NotNull] IQueryCompilationContextFactory queryCompilationContextFactory) - => new DatabaseDependencies(queryCompilationContextFactory, UpdateAdapterFactory); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// - /// A replacement for the current dependency of this type. - /// - /// A new parameter object with the given service replaced. - public DatabaseDependencies With([NotNull] IUpdateAdapterFactory updateAdapterFactory) - => new DatabaseDependencies(QueryCompilationContextFactory, updateAdapterFactory); + public IUpdateAdapterFactory UpdateAdapterFactory { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Storage/DatabaseProviderDependencies.cs b/src/EFCore/Storage/DatabaseProviderDependencies.cs index d915543a8f5..f0ca50b9979 100644 --- a/src/EFCore/Storage/DatabaseProviderDependencies.cs +++ b/src/EFCore/Storage/DatabaseProviderDependencies.cs @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class DatabaseProviderDependencies + public sealed record DatabaseProviderDependencies { /// /// diff --git a/src/EFCore/Storage/ExecutionStrategyDependencies.cs b/src/EFCore/Storage/ExecutionStrategyDependencies.cs index b9c189e0359..aa5ea92161a 100644 --- a/src/EFCore/Storage/ExecutionStrategyDependencies.cs +++ b/src/EFCore/Storage/ExecutionStrategyDependencies.cs @@ -32,7 +32,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// The implementation does not need to be thread-safe. /// /// - public sealed class ExecutionStrategyDependencies + public sealed record ExecutionStrategyDependencies { /// /// @@ -69,40 +69,16 @@ public ExecutionStrategyDependencies( /// /// The options for the current instance. /// - public IDbContextOptions Options { get; } + public IDbContextOptions Options { get; [param: CanBeNull] init; } /// /// Indirection to the current instance. /// - public ICurrentDbContext CurrentContext { get; } + public ICurrentDbContext CurrentContext { get; [param: NotNull] init; } /// /// The logger. /// - public IDiagnosticsLogger Logger { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ExecutionStrategyDependencies With([NotNull] ICurrentDbContext currentContext) - => new ExecutionStrategyDependencies(currentContext, Options, Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ExecutionStrategyDependencies With([NotNull] IDbContextOptions options) - => new ExecutionStrategyDependencies(CurrentContext, options, Logger); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ExecutionStrategyDependencies With([NotNull] IDiagnosticsLogger logger) - => new ExecutionStrategyDependencies(CurrentContext, Options, logger); + public IDiagnosticsLogger Logger { get; [param: CanBeNull] init; } } } diff --git a/src/EFCore/Storage/Internal/DatabaseFacadeDependencies.cs b/src/EFCore/Storage/Internal/DatabaseFacadeDependencies.cs index 25dd9567a91..b75db10851e 100644 --- a/src/EFCore/Storage/Internal/DatabaseFacadeDependencies.cs +++ b/src/EFCore/Storage/Internal/DatabaseFacadeDependencies.cs @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal /// The implementation does not need to be thread-safe. /// /// - public class DatabaseFacadeDependencies : IDatabaseFacadeDependencies + public record DatabaseFacadeDependencies : IDatabaseFacadeDependencies { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -54,7 +54,7 @@ public DatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IDbContextTransactionManager TransactionManager { get; } + public virtual IDbContextTransactionManager TransactionManager { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -62,7 +62,7 @@ public DatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IDatabaseCreator DatabaseCreator { get; } + public virtual IDatabaseCreator DatabaseCreator { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -70,7 +70,7 @@ public DatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IExecutionStrategyFactory ExecutionStrategyFactory { get; } + public virtual IExecutionStrategyFactory ExecutionStrategyFactory { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -78,7 +78,7 @@ public DatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IEnumerable DatabaseProviders { get; } + public virtual IEnumerable DatabaseProviders { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -86,7 +86,7 @@ public DatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IDiagnosticsLogger CommandLogger { get; } + public virtual IDiagnosticsLogger CommandLogger { get; [param: NotNull] init; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -94,6 +94,6 @@ public DatabaseFacadeDependencies( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IConcurrencyDetector ConcurrencyDetector { get; } + public virtual IConcurrencyDetector ConcurrencyDetector { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Storage/TypeMappingSourceDependencies.cs b/src/EFCore/Storage/TypeMappingSourceDependencies.cs index 24711496590..dd6556d106c 100644 --- a/src/EFCore/Storage/TypeMappingSourceDependencies.cs +++ b/src/EFCore/Storage/TypeMappingSourceDependencies.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This service cannot depend on services registered as . /// /// - public sealed class TypeMappingSourceDependencies + public sealed record TypeMappingSourceDependencies { /// /// @@ -69,27 +69,11 @@ public TypeMappingSourceDependencies( /// /// The registry of known s. /// - public IValueConverterSelector ValueConverterSelector { get; } + public IValueConverterSelector ValueConverterSelector { get; [param: NotNull] init; } /// /// Gets the plugins. /// - public IEnumerable Plugins { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public TypeMappingSourceDependencies With([NotNull] IValueConverterSelector valueConverterSelector) - => new TypeMappingSourceDependencies(valueConverterSelector, Plugins); - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public TypeMappingSourceDependencies With([NotNull] IEnumerable plugins) - => new TypeMappingSourceDependencies(ValueConverterSelector, plugins); + public IEnumerable Plugins { get; [param: NotNull] init; } } } diff --git a/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs b/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs index e9972f72282..52f196180bb 100644 --- a/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs +++ b/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion /// This service cannot depend on services registered as . /// /// - public sealed class ValueConverterSelectorDependencies + public sealed record ValueConverterSelectorDependencies { /// /// diff --git a/src/EFCore/Update/Internal/UpdateAdapterFactory.cs b/src/EFCore/Update/Internal/UpdateAdapterFactory.cs index 5fb70ab199c..b77e464048d 100644 --- a/src/EFCore/Update/Internal/UpdateAdapterFactory.cs +++ b/src/EFCore/Update/Internal/UpdateAdapterFactory.cs @@ -51,7 +51,7 @@ public virtual IUpdateAdapter CreateStandalone(IModel model = null) return model == null ? new UpdateAdapter(new StateManager(stateManager.Dependencies)) - : new UpdateAdapter(new StateManager(stateManager.Dependencies.With(model))); + : new UpdateAdapter(new StateManager(stateManager.Dependencies with { Model = model })); } } } diff --git a/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs b/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs index 0455b81c24d..b4a3cae8e59 100644 --- a/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs +++ b/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// This service cannot depend on services registered as . /// /// - public sealed class ValueGeneratorCacheDependencies + public sealed record ValueGeneratorCacheDependencies { /// /// diff --git a/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs b/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs index ec852a9d612..1ac70b97fe6 100644 --- a/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs +++ b/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// The implementation does not need to be thread-safe. /// /// - public sealed class ValueGeneratorSelectorDependencies + public sealed record ValueGeneratorSelectorDependencies { /// /// @@ -63,14 +63,6 @@ public ValueGeneratorSelectorDependencies([NotNull] IValueGeneratorCache cache) /// /// The cache being used to store value generator instances. /// - public IValueGeneratorCache Cache { get; } - - /// - /// Clones this dependency parameter object with one service replaced. - /// - /// A replacement for the current dependency of this type. - /// A new parameter object with the given service replaced. - public ValueGeneratorSelectorDependencies With([NotNull] IValueGeneratorCache cache) - => new ValueGeneratorSelectorDependencies(cache); + public IValueGeneratorCache Cache { get; [param: NotNull] init; } } } diff --git a/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs b/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs index 247db1a64bb..726d987b1e8 100644 --- a/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs +++ b/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs @@ -36,6 +36,17 @@ protected const BindingFlags PublicInstance protected const BindingFlags AnyInstance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + protected static bool IsCompilerSynthesizedMethod(MethodBase method) + => method.Name == "op_Equality" + || method.Name == "op_Inequality" + || method.Name == "PrintMembers" + // Ignore synthesized copy constructors on records + || method is ConstructorInfo + && method.GetParameters().Length == 1 + && method.GetParameters()[0] is var firstParam + && firstParam.Name == "original" + && firstParam.ParameterType == method.DeclaringType; + protected virtual TFixture Fixture { get; } [ConditionalFact] @@ -639,119 +650,6 @@ private string ValidateConventionMethod(MethodInfo conventionMethod) return null; } - [ConditionalFact] - public virtual void Ensure_dependency_objects_are_consistent() - { - var serviceCollection = new ServiceCollection(); - - AddServices(serviceCollection); - - var dependencyServices = serviceCollection.Where( - sd => sd.ServiceType.Namespace.StartsWith("Microsoft.Entity", StringComparison.Ordinal) - && sd.ServiceType.Name.EndsWith("Dependencies", StringComparison.Ordinal) - && sd.ImplementationType == sd.ServiceType) - .ToList(); - - foreach (var service in dependencyServices) - { - TestDependenciesObject(service.ImplementationType); - } - } - - // ReSharper disable once ClassNeverInstantiated.Local - private class FakeCurrentDbContext : ICurrentDbContext - { - // ReSharper disable once UnassignedGetOnlyAutoProperty - public DbContext Context { get; } - } - - private void TestDependenciesObject(Type dependenciesType) - { - if (!TryCreateProviderServices(out var serviceCollection1)) - { - return; - } - - AddServices(serviceCollection1); - var services1 = serviceCollection1.BuildServiceProvider(); - - TryCreateProviderServices(out var serviceCollection2); - AddServices(serviceCollection2); - var services2 = serviceCollection2.BuildServiceProvider(); - - var dependencies = services1.GetService(dependenciesType); - - var serviceProperties = dependenciesType.GetTypeInfo() - .DeclaredProperties - .Where(p => !Fixture.ComputedDependencyProperties.Contains(p)) - .ToList(); - - var obsoleteTypes = serviceProperties - .Where(p => p.CustomAttributes.Any(a => a.AttributeType == typeof(ObsoleteAttribute))) - .Select(p => p.PropertyType) - .ToList(); - - serviceProperties = serviceProperties.Where(p => !obsoleteTypes.Contains(p.PropertyType)).ToList(); - - var constructor = dependenciesType.GetTypeInfo().DeclaredConstructors.OrderByDescending(c => c.GetParameters().Length).First(); - var constructorParameters = constructor.GetParameters().Where(p => !obsoleteTypes.Contains(p.ParameterType)).ToList(); - - foreach (var serviceType in constructorParameters.Select(p => p.ParameterType)) - { - var withMethod = dependenciesType.GetTypeInfo().DeclaredMethods - .FirstOrDefault( - m => m.CustomAttributes.All(a => a.AttributeType != typeof(ObsoleteAttribute)) - && m.Name == "With" - && m.GetParameters()[0].ParameterType == serviceType); - - if (withMethod == null) - { - throw new Exception( - $"Expected 'With' method for service type '{serviceType.ShortDisplayName()}' on '{dependenciesType.ShortDisplayName()}'"); - } - - var clone = withMethod.Invoke(dependencies, new[] { services2.GetService(serviceType) }); - - foreach (var property in serviceProperties) - { - if (property.PropertyType == serviceType) - { - Assert.NotSame(property.GetValue(clone), property.GetValue(dependencies)); - } - else - { - Assert.Equal(property.GetValue(clone), property.GetValue(dependencies)); - } - } - } - - bool TryCreateProviderServices(out ServiceCollection services) - { - if (!Fixture.TryGetProviderOptionsDelegate(out var optionsDelegate)) - { - services = null; - return false; - } - - services = (ServiceCollection)new ServiceCollection() - .AddScoped(p => CreateOptions(p, optionsDelegate)) - .AddScoped() - .AddScoped(); - - return true; - } - - DbContextOptions CreateOptions(IServiceProvider serviceProvider, Action optionsDelegate) - { - var optionsBuilder = new DbContextOptionsBuilder() - .UseInternalServiceProvider(serviceProvider); - - optionsDelegate(optionsBuilder); - - return optionsBuilder.Options; - } - } - [ConditionalFact] public virtual void Service_implementations_should_use_dependencies_parameter_object() { @@ -842,6 +740,7 @@ from method in type.GetMethods(AnyInstance | BindingFlags.Static | BindingFlags. type.GetConstructors( BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static)) where (method.IsPublic || method.IsFamily || method.IsFamilyOrAssembly) + && !IsCompilerSynthesizedMethod(method) && !Fixture.NotAnnotatedMethods.Contains(method) && (method is ConstructorInfo || ((MethodInfo)method).GetBaseDefinition().DeclaringType == method.DeclaringType) && (type.IsInterface || !interfaceMappings.Any(im => im.TargetMethods.Contains(method))) @@ -890,11 +789,12 @@ from parameter in method.GetParameters() || parameterType.IsValueType && parameterType.IsNullableType() && attributes.Any(a => a.GetType().Name == nameof(CanBeNullAttribute)) - select $"{type.FullName}.{method.Name}[{parameter.Name}]").ToList(); + select (Type: type, Method: method, Parameter: parameter)).ToList(); Assert.False( parametersWithRedundantAttribute.Count > 0, - "\r\n-- Redundant NotNull annotations --\r\n" + string.Join(Environment.NewLine, parametersWithRedundantAttribute)); + "\r\n-- Redundant NotNull annotations --\r\n" + string.Join(Environment.NewLine, + parametersWithRedundantAttribute.Select(t => $"{t.Type.FullName}.{t.Method.Name}[{t.Parameter.Name}]"))); } private static readonly HashSet _nonCancellableAsyncMethods = new HashSet(); diff --git a/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs b/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs index c8c7e22681c..fd4bc44d080 100644 --- a/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs +++ b/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs @@ -163,7 +163,7 @@ public ModelBuilder CreateConventionBuilder( return new ModelBuilder( contextServices.GetRequiredService().CreateConventionSet(), - contextServices.GetRequiredService().With(modelLogger)); + contextServices.GetRequiredService() with { Logger = modelLogger }); } public ConventionSet CreateConventionalConventionSet( diff --git a/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs index 5ab4e0fb6fd..e0e6fda7dfa 100644 --- a/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs @@ -1171,7 +1171,7 @@ private ForeignKeyPropertyDiscoveryConvention CreateForeignKeyPropertyDiscoveryC private ProviderConventionSetBuilderDependencies CreateDependencies() => InMemoryTestHelpers.Instance.CreateContextServices().GetRequiredService() - .With(CreateLogger()); + with { Logger = CreateLogger() }; private DiagnosticsLogger CreateLogger() { diff --git a/test/EFCore.Tests/Metadata/Conventions/KeyDiscoveryConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/KeyDiscoveryConventionTest.cs index a2a34463d49..8c2c874c6f1 100644 --- a/test/EFCore.Tests/Metadata/Conventions/KeyDiscoveryConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/KeyDiscoveryConventionTest.cs @@ -159,7 +159,7 @@ private KeyDiscoveryConvention CreateKeyDiscoveryConvention() private ProviderConventionSetBuilderDependencies CreateDependencies() => InMemoryTestHelpers.Instance.CreateContextServices().GetRequiredService() - .With(CreateLogger()); + with { Logger = CreateLogger()}; private DiagnosticsLogger CreateLogger() { diff --git a/test/EFCore.Tests/Metadata/Conventions/ManyToManyJoinEntityTypeConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/ManyToManyJoinEntityTypeConventionTest.cs index ab1edbcc0ab..f500a7b6c7d 100644 --- a/test/EFCore.Tests/Metadata/Conventions/ManyToManyJoinEntityTypeConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/ManyToManyJoinEntityTypeConventionTest.cs @@ -280,7 +280,7 @@ private ManyToManyJoinEntityTypeConvention CreateManyToManyConvention() private ProviderConventionSetBuilderDependencies CreateDependencies() => InMemoryTestHelpers.Instance.CreateContextServices().GetRequiredService() - .With(CreateLogger()); + with { Logger = CreateLogger() }; private InternalModelBuilder CreateInternalModeBuilder() => new Model().Builder; diff --git a/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs index 1f9fcbfcef8..e15f6131227 100644 --- a/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs @@ -1174,7 +1174,7 @@ private void Cleanup(InternalModelBuilder modelBuilder) private ProviderConventionSetBuilderDependencies CreateDependencies() => InMemoryTestHelpers.Instance.CreateContextServices().GetRequiredService() - .With(CreateLogger()); + with { Logger = CreateLogger() }; private InternalModelBuilder CreateInternalModeBuilder(params Action[] onEntityAdded) { diff --git a/test/EFCore.Tests/ModelSourceTest.cs b/test/EFCore.Tests/ModelSourceTest.cs index be84d0bb997..4c4b91afde9 100644 --- a/test/EFCore.Tests/ModelSourceTest.cs +++ b/test/EFCore.Tests/ModelSourceTest.cs @@ -85,8 +85,8 @@ public void Adds_all_entities_based_on_all_distinct_entity_types_found() context, new RuntimeConventionSetBuilder( new ProviderConventionSetBuilder( - serviceProvider.GetRequiredService() - .With(setFinder)), new List()), + serviceProvider.GetRequiredService() with { SetFinder = setFinder }), + new List()), serviceProvider.GetRequiredService()); Assert.Equal(