Skip to content

Commit

Permalink
Add With methods for cloning dependency objects with service replacement
Browse files Browse the repository at this point in the history
Issue #7465
  • Loading branch information
ajcvickers committed Feb 24, 2017
1 parent dcde6b1 commit b992764
Show file tree
Hide file tree
Showing 68 changed files with 1,950 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,21 @@ public RelationalModelValidatorDependencies(
/// Gets the type mapper.
/// </summary>
public IRelationalTypeMapper TypeMapper { get; }

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="relationalExtensions"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public RelationalModelValidatorDependencies With([NotNull] IRelationalAnnotationProvider relationalExtensions)
=> new RelationalModelValidatorDependencies(relationalExtensions, TypeMapper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="typeMapper"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public RelationalModelValidatorDependencies With([NotNull] IRelationalTypeMapper typeMapper)
=> new RelationalModelValidatorDependencies(RelationalExtensions, typeMapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,29 @@ public RelationalConventionSetBuilderDependencies(
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public IDbSetFinder SetFinder { get; }

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="typeMapper"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public RelationalConventionSetBuilderDependencies With([NotNull] IRelationalTypeMapper typeMapper)
=> new RelationalConventionSetBuilderDependencies(typeMapper, Context, SetFinder);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="currentContext"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public RelationalConventionSetBuilderDependencies With([NotNull] ICurrentDbContext currentContext)
=> new RelationalConventionSetBuilderDependencies(TypeMapper, currentContext, SetFinder);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="setFinder"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public RelationalConventionSetBuilderDependencies With([NotNull] IDbSetFinder setFinder)
=> new RelationalConventionSetBuilderDependencies(TypeMapper, Context, setFinder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ namespace Microsoft.EntityFrameworkCore.Migrations
/// </para>
/// <para>
/// Do not construct instances of this class directly from either provider or application code as the
/// constructor signature may change as new dependencies are added. Instead, use this type in
/// your constructor so that an instance will be created and injected automatically by the
/// dependency injection container. To create an instance with some dependent services replaced,
/// first resolve the object from the dependency injection container, then replace selected
/// constructor signature may change as new dependencies are added. Instead, use this type in
/// your constructor so that an instance will be created and injected automatically by the
/// dependency injection container. To create an instance with some dependent services replaced,
/// first resolve the object from the dependency injection container, then replace selected
/// services using the 'With...' methods. Do not call the constructor at any point in this process.
/// </para>
/// <para>
/// Do not construct instances of this class directly from either provider or application code as the
/// constructor signature may change as new dependencies are added. Instead, use this type in
/// your constructor so that an instance will be created and injected automatically by the
/// dependency injection container. To create an instance with some dependent services replaced,
/// first resolve the object from the dependency injection container, then replace selected
/// constructor signature may change as new dependencies are added. Instead, use this type in
/// your constructor so that an instance will be created and injected automatically by the
/// dependency injection container. To create an instance with some dependent services replaced,
/// first resolve the object from the dependency injection container, then replace selected
/// services using the 'With...' methods. Do not call the constructor at any point in this process.
/// </para>
/// </summary>
Expand All @@ -41,11 +41,11 @@ public sealed class HistoryRepositoryDependencies
/// Creates the service dependencies parameter object for a <see cref="HistoryRepository" />.
/// </para>
/// <para>
/// Do not call this constructor directly from either provider or application code as it may change
/// as new dependencies are added. Instead, use this type in your constructor so that an instance
/// will be created and injected automatically by the dependency injection container. To create
/// an instance with some dependent services replaced, first resolve the object from the dependency
/// injection container, then replace selected services using the 'With...' methods. Do not call
/// Do not call this constructor directly from either provider or application code as it may change
/// as new dependencies are added. Instead, use this type in your constructor so that an instance
/// will be created and injected automatically by the dependency injection container. To create
/// an instance with some dependent services replaced, first resolve the object from the dependency
/// injection container, then replace selected services using the 'With...' methods. Do not call
/// the constructor at any point in this process.
/// </para>
/// <para>
Expand All @@ -62,7 +62,7 @@ public sealed class HistoryRepositoryDependencies
/// <param name="annotations"> Access to relational metadata for the model. </param>
/// <param name="sqlGenerationHelper"> Helpers for generating update SQL. </param>
public HistoryRepositoryDependencies(
[NotNull] IDatabaseCreator databaseCreator,
[NotNull] IRelationalDatabaseCreator databaseCreator,
[NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
[NotNull] IRelationalConnection connection,
[NotNull] IDbContextOptions options,
Expand All @@ -80,7 +80,7 @@ public HistoryRepositoryDependencies(
Check.NotNull(annotations, nameof(annotations));
Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));

DatabaseCreator = (IRelationalDatabaseCreator)databaseCreator;
DatabaseCreator = databaseCreator;
RawSqlCommandBuilder = rawSqlCommandBuilder;
Connection = connection;
Options = options;
Expand Down Expand Up @@ -129,5 +129,133 @@ public HistoryRepositoryDependencies(
/// Helpers for generating update SQL.
/// </summary>
public ISqlGenerationHelper SqlGenerationHelper { get; }

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="databaseCreator"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] IRelationalDatabaseCreator databaseCreator)
=> new HistoryRepositoryDependencies(
databaseCreator,
RawSqlCommandBuilder,
Connection,
Options,
ModelDiffer,
MigrationsSqlGenerator,
Annotations,
SqlGenerationHelper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="rawSqlCommandBuilder"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder)
=> new HistoryRepositoryDependencies(
DatabaseCreator,
rawSqlCommandBuilder,
Connection,
Options,
ModelDiffer,
MigrationsSqlGenerator,
Annotations,
SqlGenerationHelper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="connection"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] IRelationalConnection connection)
=> new HistoryRepositoryDependencies(
DatabaseCreator,
RawSqlCommandBuilder,
connection,
Options,
ModelDiffer,
MigrationsSqlGenerator,
Annotations,
SqlGenerationHelper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="options"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] IDbContextOptions options)
=> new HistoryRepositoryDependencies(
DatabaseCreator,
RawSqlCommandBuilder,
Connection,
options,
ModelDiffer,
MigrationsSqlGenerator,
Annotations,
SqlGenerationHelper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="modelDiffer"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] IMigrationsModelDiffer modelDiffer)
=> new HistoryRepositoryDependencies(
DatabaseCreator,
RawSqlCommandBuilder,
Connection,
Options,
modelDiffer,
MigrationsSqlGenerator,
Annotations,
SqlGenerationHelper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="migrationsSqlGenerator"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] IMigrationsSqlGenerator migrationsSqlGenerator)
=> new HistoryRepositoryDependencies(
DatabaseCreator,
RawSqlCommandBuilder,
Connection,
Options,
ModelDiffer,
migrationsSqlGenerator,
Annotations,
SqlGenerationHelper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="annotations"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] IRelationalAnnotationProvider annotations)
=> new HistoryRepositoryDependencies(
DatabaseCreator,
RawSqlCommandBuilder,
Connection,
Options,
ModelDiffer,
MigrationsSqlGenerator,
annotations,
SqlGenerationHelper);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="sqlGenerationHelper"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public HistoryRepositoryDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper)
=> new HistoryRepositoryDependencies(
DatabaseCreator,
RawSqlCommandBuilder,
Connection,
Options,
ModelDiffer,
MigrationsSqlGenerator,
Annotations,
sqlGenerationHelper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace Microsoft.EntityFrameworkCore.Migrations
/// </para>
/// <para>
/// Do not construct instances of this class directly from either provider or application code as the
/// constructor signature may change as new dependencies are added. Instead, use this type in
/// your constructor so that an instance will be created and injected automatically by the
/// dependency injection container. To create an instance with some dependent services replaced,
/// first resolve the object from the dependency injection container, then replace selected
/// constructor signature may change as new dependencies are added. Instead, use this type in
/// your constructor so that an instance will be created and injected automatically by the
/// dependency injection container. To create an instance with some dependent services replaced,
/// first resolve the object from the dependency injection container, then replace selected
/// services using the 'With...' methods. Do not call the constructor at any point in this process.
/// </para>
/// </summary>
Expand All @@ -32,11 +32,11 @@ public sealed class MigrationsSqlGeneratorDependencies
/// Creates the service dependencies parameter object for a <see cref="MigrationsSqlGenerator" />.
/// </para>
/// <para>
/// Do not call this constructor directly from either provider or application code as it may change
/// as new dependencies are added. Instead, use this type in your constructor so that an instance
/// will be created and injected automatically by the dependency injection container. To create
/// an instance with some dependent services replaced, first resolve the object from the dependency
/// injection container, then replace selected services using the 'With...' methods. Do not call
/// Do not call this constructor directly from either provider or application code as it may change
/// as new dependencies are added. Instead, use this type in your constructor so that an instance
/// will be created and injected automatically by the dependency injection container. To create
/// an instance with some dependent services replaced, first resolve the object from the dependency
/// injection container, then replace selected services using the 'With...' methods. Do not call
/// the constructor at any point in this process.
/// </para>
/// <para>
Expand Down Expand Up @@ -84,5 +84,53 @@ public MigrationsSqlGeneratorDependencies(
/// Helpers for obtaining relational metadata.
/// </summary>
public IRelationalAnnotationProvider Annotations { get; }

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="commandBuilderFactory"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public MigrationsSqlGeneratorDependencies With([NotNull] IRelationalCommandBuilderFactory commandBuilderFactory)
=> new MigrationsSqlGeneratorDependencies(
commandBuilderFactory,
SqlGenerationHelper,
TypeMapper,
Annotations);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="sqlGenerationHelper"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public MigrationsSqlGeneratorDependencies With([NotNull] ISqlGenerationHelper sqlGenerationHelper)
=> new MigrationsSqlGeneratorDependencies(
CommandBuilderFactory,
sqlGenerationHelper,
TypeMapper,
Annotations);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="typeMapper"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public MigrationsSqlGeneratorDependencies With([NotNull] IRelationalTypeMapper typeMapper)
=> new MigrationsSqlGeneratorDependencies(
CommandBuilderFactory,
SqlGenerationHelper,
typeMapper,
Annotations);

/// <summary>
/// Clones this dependency parameter object with one service replaced.
/// </summary>
/// <param name="annotations"> A replacement for the current dependency of this type. </param>
/// <returns> A new parameter object with the given service replaced. </returns>
public MigrationsSqlGeneratorDependencies With([NotNull] IRelationalAnnotationProvider annotations)
=> new MigrationsSqlGeneratorDependencies(
CommandBuilderFactory,
SqlGenerationHelper,
TypeMapper,
annotations);
}
}
Loading

0 comments on commit b992764

Please sign in to comment.