diff --git a/src/EFCore.Cosmos/Extensions/CosmosDatabaseFacadeExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosDatabaseFacadeExtensions.cs index dc9e8f08d73..8ded48ec5be 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosDatabaseFacadeExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosDatabaseFacadeExtensions.cs @@ -26,7 +26,7 @@ public static class CosmosDatabaseFacadeExtensions /// The for the context. /// The public static CosmosClient GetCosmosClient([NotNull] this DatabaseFacade databaseFacade) - => GetService(databaseFacade).Client; + => GetService(databaseFacade).Client; private static TService GetService(IInfrastructure databaseFacade) { diff --git a/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs index c1b47b1b2d7..a2e858ea668 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs @@ -70,12 +70,12 @@ public static IServiceCollection AddEntityFrameworkCosmos([NotNull] this IServic .TryAddProviderSpecificServices( b => b .TryAddSingleton() - .TryAddSingleton() + .TryAddSingleton() .TryAddSingleton() .TryAddSingleton() .TryAddSingleton() .TryAddSingleton() - .TryAddScoped() + .TryAddScoped() ); builder.TryAddCoreServices(); diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs index e34099f7ee2..50a5e7af84e 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs @@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Utilities; -using Microsoft.EntityFrameworkCore.ValueGeneration; #nullable enable @@ -27,7 +26,7 @@ public class CosmosQueryContext : QueryContext /// public CosmosQueryContext( [NotNull] QueryContextDependencies dependencies, - [NotNull] CosmosClientWrapper cosmosClient) + [NotNull] ICosmosClientWrapper cosmosClient) : base(dependencies) { Check.NotNull(cosmosClient, nameof(cosmosClient)); @@ -41,6 +40,6 @@ public CosmosQueryContext( /// 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 CosmosClientWrapper CosmosClient { get; } + public virtual ICosmosClientWrapper CosmosClient { get; } } } diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs index a5797d79c3e..d167e9e6021 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs @@ -19,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal public class CosmosQueryContextFactory : IQueryContextFactory { private readonly QueryContextDependencies _dependencies; - private readonly CosmosClientWrapper _cosmosClient; + private readonly ICosmosClientWrapper _cosmosClient; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -29,7 +29,7 @@ public class CosmosQueryContextFactory : IQueryContextFactory /// public CosmosQueryContextFactory( [NotNull] QueryContextDependencies dependencies, - [NotNull] CosmosClientWrapper cosmosClient) + [NotNull] ICosmosClientWrapper cosmosClient) { Check.NotNull(dependencies, nameof(dependencies)); Check.NotNull(cosmosClient, nameof(cosmosClient)); diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs index 73e9c6bb4de..344e8460463 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs @@ -42,7 +42,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal /// The implementation does not need to be thread-safe. /// /// - public class CosmosClientWrapper + public class CosmosClientWrapper : ICosmosClientWrapper { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -60,7 +60,7 @@ public class CosmosClientWrapper /// public static readonly string DefaultPartitionKey = "__partitionKey"; - private readonly SingletonCosmosClientWrapper _singletonWrapper; + private readonly ISingletonCosmosClientWrapper _singletonWrapper; private readonly string _databaseId; private readonly IExecutionStrategyFactory _executionStrategyFactory; private readonly IDiagnosticsLogger _commandLogger; @@ -79,7 +79,7 @@ static CosmosClientWrapper() /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public CosmosClientWrapper( - [NotNull] SingletonCosmosClientWrapper singletonWrapper, + [NotNull] ISingletonCosmosClientWrapper singletonWrapper, [NotNull] IDbContextOptions dbContextOptions, [NotNull] IExecutionStrategyFactory executionStrategyFactory, [NotNull] IDiagnosticsLogger commandLogger) @@ -205,8 +205,8 @@ public virtual async Task DeleteDatabaseOnceAsync( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CreateContainerIfNotExists( - [NotNull] string containerId, - [NotNull] string partitionKey) + string containerId, + string partitionKey) => _executionStrategyFactory.Create().Execute( (containerId, partitionKey), CreateContainerIfNotExistsOnce, null); @@ -222,8 +222,8 @@ private bool CreateContainerIfNotExistsOnce( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual Task CreateContainerIfNotExistsAsync( - [NotNull] string containerId, - [NotNull] string partitionKey, + string containerId, + string partitionKey, CancellationToken cancellationToken = default) => _executionStrategyFactory.Create().ExecuteAsync( (containerId, partitionKey), CreateContainerIfNotExistsOnceAsync, null, cancellationToken); @@ -256,9 +256,9 @@ private async Task CreateContainerIfNotExistsOnceAsync( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CreateItem( - [NotNull] string containerId, - [NotNull] JToken document, - [NotNull] IUpdateEntry entry) + string containerId, + JToken document, + IUpdateEntry entry) => _executionStrategyFactory.Create().Execute( (containerId, document, entry), CreateItemOnce, null); @@ -274,9 +274,9 @@ private bool CreateItemOnce( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual Task CreateItemAsync( - [NotNull] string containerId, - [NotNull] JToken document, - [NotNull] IUpdateEntry updateEntry, + string containerId, + JToken document, + IUpdateEntry updateEntry, CancellationToken cancellationToken = default) => _executionStrategyFactory.Create().ExecuteAsync( (containerId, document, updateEntry), CreateItemOnceAsync, null, cancellationToken); @@ -311,10 +311,10 @@ private async Task CreateItemOnceAsync( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool ReplaceItem( - [NotNull] string collectionId, - [NotNull] string documentId, - [NotNull] JObject document, - [NotNull] IUpdateEntry entry) + string collectionId, + string documentId, + JObject document, + IUpdateEntry entry) => _executionStrategyFactory.Create().Execute( (collectionId, documentId, document, entry), ReplaceItemOnce, @@ -332,10 +332,10 @@ private bool ReplaceItemOnce( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual Task ReplaceItemAsync( - [NotNull] string collectionId, - [NotNull] string documentId, - [NotNull] JObject document, - [NotNull] IUpdateEntry updateEntry, + string collectionId, + string documentId, + JObject document, + IUpdateEntry updateEntry, CancellationToken cancellationToken = default) => _executionStrategyFactory.Create().ExecuteAsync( (collectionId, documentId, document, updateEntry), @@ -374,9 +374,9 @@ private async Task ReplaceItemOnceAsync( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool DeleteItem( - [NotNull] string containerId, - [NotNull] string documentId, - [NotNull] IUpdateEntry entry) + string containerId, + string documentId, + IUpdateEntry entry) => _executionStrategyFactory.Create().Execute( (containerId, documentId, entry), DeleteItemOnce, null); @@ -398,9 +398,9 @@ public virtual bool DeleteItemOnce( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual Task DeleteItemAsync( - [NotNull] string containerId, - [NotNull] string documentId, - [NotNull] IUpdateEntry entry, + string containerId, + string documentId, + IUpdateEntry entry, CancellationToken cancellationToken = default) => _executionStrategyFactory.Create().ExecuteAsync( (containerId, documentId, entry), DeleteItemOnceAsync, null, cancellationToken); @@ -500,9 +500,9 @@ private static void ProcessResponse(ResponseMessage response, IUpdateEntry entry /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual IEnumerable ExecuteSqlQuery( - [NotNull] string containerId, - [CanBeNull] string partitionKey, - [NotNull] CosmosSqlQuery query) + string containerId, + string partitionKey, + CosmosSqlQuery query) { _commandLogger.ExecutingSqlQuery(query); @@ -516,9 +516,9 @@ public virtual IEnumerable ExecuteSqlQuery( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual IAsyncEnumerable ExecuteSqlQueryAsync( - [NotNull] string containerId, - [CanBeNull] string partitionKey, - [NotNull] CosmosSqlQuery query) + string containerId, + string partitionKey, + CosmosSqlQuery query) { _commandLogger.ExecutingSqlQuery(query); @@ -532,9 +532,9 @@ public virtual IAsyncEnumerable ExecuteSqlQueryAsync( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual JObject ExecuteReadItem( - [NotNull] string containerId, - [CanBeNull] string partitionKey, - [NotNull] string resourceId) + string containerId, + string partitionKey, + string resourceId) { _commandLogger.ExecutingReadItem(partitionKey, resourceId); @@ -550,10 +550,10 @@ public virtual JObject ExecuteReadItem( /// 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. /// - internal virtual async Task ExecuteReadItemAsync( - [NotNull] string containerId, - [CanBeNull] string partitionKey, - [NotNull] string resourceId, + public virtual async Task ExecuteReadItemAsync( + string containerId, + string partitionKey, + string resourceId, CancellationToken cancellationToken = default) { _commandLogger.ExecutingReadItem(partitionKey, resourceId); @@ -578,7 +578,13 @@ private static JObject JObjectFromReadItemResponseMessage(ResponseMessage respon return new JObject(new JProperty("c", jObject)); } - private FeedIterator CreateQuery( + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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 FeedIterator CreateQuery( string containerId, string partitionKey, CosmosSqlQuery query) @@ -656,13 +662,13 @@ private static bool TryReadJObject(JsonTextReader jsonReader, out JObject jObjec private sealed class DocumentEnumerable : IEnumerable { - private readonly CosmosClientWrapper _cosmosClient; + private readonly ICosmosClientWrapper _cosmosClient; private readonly string _containerId; private readonly string _partitionKey; private readonly CosmosSqlQuery _cosmosSqlQuery; public DocumentEnumerable( - CosmosClientWrapper cosmosClient, + ICosmosClientWrapper cosmosClient, string containerId, string partitionKey, CosmosSqlQuery cosmosSqlQuery) @@ -681,7 +687,7 @@ IEnumerator IEnumerable.GetEnumerator() private sealed class Enumerator : IEnumerator { - private readonly CosmosClientWrapper _cosmosClientWrapper; + private readonly ICosmosClientWrapper _cosmosClientWrapper; private readonly string _containerId; private readonly string _partitionKey; private readonly CosmosSqlQuery _cosmosSqlQuery; @@ -763,13 +769,13 @@ public void Reset() private sealed class DocumentAsyncEnumerable : IAsyncEnumerable { - private readonly CosmosClientWrapper _cosmosClient; + private readonly ICosmosClientWrapper _cosmosClient; private readonly string _containerId; private readonly string _partitionKey; private readonly CosmosSqlQuery _cosmosSqlQuery; public DocumentAsyncEnumerable( - CosmosClientWrapper cosmosClient, + ICosmosClientWrapper cosmosClient, string containerId, string partitionKey, CosmosSqlQuery cosmosSqlQuery) @@ -785,7 +791,7 @@ public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellati private sealed class AsyncEnumerator : IAsyncEnumerator { - private readonly CosmosClientWrapper _cosmosClientWrapper; + private readonly ICosmosClientWrapper _cosmosClientWrapper; private readonly string _containerId; private readonly string _partitionKey; private readonly CosmosSqlQuery _cosmosSqlQuery; diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs index 3d4740318cb..0019fdd0c68 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs @@ -19,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal /// public class CosmosDatabaseCreator : IDatabaseCreator { - private readonly CosmosClientWrapper _cosmosClient; + private readonly ICosmosClientWrapper _cosmosClient; private readonly IModel _model; private readonly IUpdateAdapterFactory _updateAdapterFactory; private readonly IDatabase _database; @@ -31,7 +31,7 @@ public class CosmosDatabaseCreator : IDatabaseCreator /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public CosmosDatabaseCreator( - [NotNull] CosmosClientWrapper cosmosClient, + [NotNull] ICosmosClientWrapper cosmosClient, [NotNull] IModel model, [NotNull] IUpdateAdapterFactory updateAdapterFactory, [NotNull] IDatabase database) diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs index b484ea75163..0bcd63c60e1 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs @@ -39,10 +39,9 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal /// public class CosmosDatabaseWrapper : EntityFrameworkCore.Storage.Database { - private readonly Dictionary _documentCollections - = new Dictionary(); + private readonly Dictionary _documentCollections = new(); - private readonly CosmosClientWrapper _cosmosClient; + private readonly ICosmosClientWrapper _cosmosClient; private readonly bool _sensitiveLoggingEnabled; /// @@ -53,7 +52,7 @@ private readonly Dictionary _documentCollections /// public CosmosDatabaseWrapper( [NotNull] DatabaseDependencies dependencies, - [NotNull] CosmosClientWrapper cosmosClient, + [NotNull] ICosmosClientWrapper cosmosClient, [NotNull] ILoggingOptions loggingOptions) : base(dependencies) { diff --git a/src/EFCore.Cosmos/Storage/Internal/ICosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/ICosmosClientWrapper.cs new file mode 100644 index 00000000000..e60c63e3827 --- /dev/null +++ b/src/EFCore.Cosmos/Storage/Internal/ICosmosClientWrapper.cs @@ -0,0 +1,194 @@ +// 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 System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using JetBrains.Annotations; +using Microsoft.Azure.Cosmos; +using Microsoft.EntityFrameworkCore.Update; +using Newtonsoft.Json.Linq; + +namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal +{ + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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 interface ICosmosClientWrapper + { + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + Task CreateDatabaseIfNotExistsAsync(CancellationToken cancellationToken = default); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + bool CreateDatabaseIfNotExists(); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + bool CreateContainerIfNotExists([NotNull] string containerId, [NotNull] string partitionKey); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + Task CreateContainerIfNotExistsAsync( + [NotNull] string containerId, + [NotNull] string partitionKey, + CancellationToken cancellationToken = default); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + bool DeleteDatabase(); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + Task DeleteDatabaseAsync(CancellationToken cancellationToken = default); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + bool CreateItem([NotNull] string containerId, [NotNull] JToken document, [NotNull] IUpdateEntry entry); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + bool ReplaceItem( + [NotNull] string collectionId, + [NotNull] string documentId, + [NotNull] JObject document, + [NotNull] IUpdateEntry entry); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + bool DeleteItem( + [NotNull] string containerId, + [NotNull] string documentId, + [NotNull] IUpdateEntry entry); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + Task CreateItemAsync( + [NotNull] string containerId, + [NotNull] JToken document, + [NotNull] IUpdateEntry updateEntry, + CancellationToken cancellationToken = default); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + Task ReplaceItemAsync( + [NotNull] string collectionId, + [NotNull] string documentId, + [NotNull] JObject document, + [NotNull] IUpdateEntry updateEntry, + CancellationToken cancellationToken = default); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + Task DeleteItemAsync( + [NotNull] string containerId, + [NotNull] string documentId, + [NotNull] IUpdateEntry entry, + CancellationToken cancellationToken = default); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + FeedIterator CreateQuery([NotNull] string containerId, [NotNull] string partitionKey, [NotNull] CosmosSqlQuery query); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + JObject ExecuteReadItem( + [NotNull] string containerId, + [CanBeNull] string partitionKey, + [NotNull] string resourceId); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + Task ExecuteReadItemAsync( + [NotNull] string containerId, + [CanBeNull] string partitionKey, + [NotNull] string resourceId, + CancellationToken cancellationToken = default); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + IEnumerable ExecuteSqlQuery( + [NotNull] string containerId, + [CanBeNull] string partitionKey, + [NotNull] CosmosSqlQuery query); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + IAsyncEnumerable ExecuteSqlQueryAsync( + [NotNull] string containerId, + [CanBeNull] string partitionKey, + [NotNull] CosmosSqlQuery query); + } +} diff --git a/src/EFCore.Cosmos/Storage/Internal/ISingletonCosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/ISingletonCosmosClientWrapper.cs new file mode 100644 index 00000000000..b9f5c2d02e9 --- /dev/null +++ b/src/EFCore.Cosmos/Storage/Internal/ISingletonCosmosClientWrapper.cs @@ -0,0 +1,34 @@ +// 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 System; +using Microsoft.Azure.Cosmos; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal +{ + /// + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + /// + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many + /// instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . + /// + /// + public interface ISingletonCosmosClientWrapper : IDisposable + { + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + CosmosClient Client { get; } + } +} diff --git a/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs index 00a33e26fe4..fa2e684d532 100644 --- a/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs @@ -1,7 +1,6 @@ // 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 System; using JetBrains.Annotations; using Microsoft.Azure.Cosmos; using Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal; @@ -24,7 +23,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal /// This service cannot depend on services registered as . /// /// - public class SingletonCosmosClientWrapper : IDisposable + public class SingletonCosmosClientWrapper : ISingletonCosmosClientWrapper { private static readonly string _userAgent = " Microsoft.EntityFrameworkCore.Cosmos/" + ProductInfo.GetVersion(); private readonly CosmosClientOptions _options; diff --git a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs index 66104927428..432e1c5c744 100644 --- a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs +++ b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs @@ -103,7 +103,7 @@ private async Task CreateFromFile(DbContext context) { if (await context.Database.EnsureCreatedAsync()) { - var cosmosClient = context.GetService(); + var cosmosClient = context.GetService(); var serializer = CosmosClientWrapper.Serializer; using var fs = new FileStream(_dataFilePath, FileMode.Open, FileAccess.Read); using var sr = new StreamReader(fs); @@ -163,7 +163,7 @@ public override void Clean(DbContext context) public override async Task CleanAsync(DbContext context) { - var cosmosClientWrapper = context.GetService(); + var cosmosClientWrapper = context.GetService(); var created = await cosmosClientWrapper.CreateDatabaseIfNotExistsAsync(); try {