-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Service dependencies parameter class for RelationalConnection
This is a proof-of-concept implementation of parameter objects for service dependencies. Issue #7465. Notes: - Parameter class is sealed. - Ended up going with Clone on the parameters object--cleaner than other things I tried, and general purpose. We can add overloads of Clone as needed when doing point releases without breaking existing code. (May want to consider whether parameter should be options.) - Registration is not try-add and is of concrete class
- Loading branch information
1 parent
532195c
commit 7b62116
Showing
10 changed files
with
143 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/Microsoft.EntityFrameworkCore.Relational/Storage/RelationalConnectionDependencies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Service dependencies parameter class for <see cref="RelationalConnection" /> | ||
/// </para> | ||
/// <para> | ||
/// This type is typically used by database providers (and other extensions). It is generally | ||
/// not used in application code. | ||
/// </para> | ||
/// </summary> | ||
public sealed class RelationalConnectionDependencies | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Creates the service dependencies parameter object for a <see cref="RelationalConnection" />. | ||
/// </para> | ||
/// <para> | ||
/// Do not call this constructor directly from provider or application code as it may change | ||
/// as new dependencies are added. Use the <see cref="Clone" /> method instead. | ||
/// </para> | ||
/// </summary> | ||
/// <param name="contextOptions"> The options for the current context instance. </param> | ||
/// <param name="logger"> The logger to write to. </param> | ||
public RelationalConnectionDependencies( | ||
[NotNull] IDbContextOptions contextOptions, | ||
[NotNull] ILogger<IRelationalConnection> logger) | ||
{ | ||
Check.NotNull(contextOptions, nameof(contextOptions)); | ||
Check.NotNull(logger, nameof(logger)); | ||
|
||
ContextOptions = contextOptions; | ||
Logger = logger; | ||
} | ||
|
||
/// <summary> | ||
/// The options for the current context instance. | ||
/// </summary> | ||
public IDbContextOptions ContextOptions { get; } | ||
|
||
/// <summary> | ||
/// The logger to write to. | ||
/// </summary> | ||
public ILogger<IRelationalConnection> Logger { get; } | ||
|
||
/// <summary> | ||
/// Clones this dependency parameter object, optionally replacing existing dependencies. | ||
/// </summary> | ||
/// <param name="contextOptions"> | ||
/// A replacement for the current dependency of this type, or null to continue to use the current dependency. | ||
/// </param> | ||
/// <param name="logger"> | ||
/// A replacement for the current dependency of this type, or null to continue to use the current dependency. | ||
/// </param> | ||
/// <returns></returns> | ||
public RelationalConnectionDependencies Clone( | ||
[CanBeNull] IDbContextOptions contextOptions = null, | ||
[CanBeNull] ILogger<IRelationalConnection> logger = null) | ||
=> new RelationalConnectionDependencies( | ||
contextOptions ?? ContextOptions, | ||
logger ?? Logger); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.