From c75e5881b244d0cae4636d719d6cad8dc5701edb Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Thu, 10 May 2018 21:38:47 +0100 Subject: [PATCH 1/8] Simplified the manual initialisation of a CosmosStore --- Cosmonaut/Cosmonaut.csproj | 2 +- Cosmonaut/CosmosStore.cs | 16 ++++++++-------- .../CosmonautServiceCollectionExtensions.cs | 9 +++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Cosmonaut/Cosmonaut.csproj b/Cosmonaut/Cosmonaut.csproj index 314e60c..28c2235 100644 --- a/Cosmonaut/Cosmonaut.csproj +++ b/Cosmonaut/Cosmonaut.csproj @@ -12,7 +12,7 @@ https://github.com/Elfocrash/Cosmonaut cosmosdb azure cosmos entitystore entity db orm Please report any issues on Github. - 1.3.4 + 1.4.0 diff --git a/Cosmonaut/CosmosStore.cs b/Cosmonaut/CosmosStore.cs index 0a80da5..4046a39 100644 --- a/Cosmonaut/CosmosStore.cs +++ b/Cosmonaut/CosmosStore.cs @@ -34,32 +34,32 @@ public sealed class CosmosStore : ICosmosStore where TEntity : private readonly CosmosScaler _cosmosScaler; public CosmosStore(CosmosStoreSettings settings, - IDatabaseCreator databaseCreator, - ICollectionCreator collectionCreator) + IDatabaseCreator databaseCreator = null, + ICollectionCreator collectionCreator = null) { Settings = settings ?? throw new ArgumentNullException(nameof(settings)); var endpointUrl = Settings.EndpointUrl ?? throw new ArgumentNullException(nameof(Settings.EndpointUrl)); var authKey = Settings.AuthKey ?? throw new ArgumentNullException(nameof(Settings.AuthKey)); DocumentClient = DocumentClientFactory.CreateDocumentClient(endpointUrl, authKey); if (string.IsNullOrEmpty(Settings.DatabaseName)) throw new ArgumentNullException(nameof(Settings.DatabaseName)); - _collectionCreator = collectionCreator ?? throw new ArgumentNullException(nameof(collectionCreator)); - _databaseCreator = databaseCreator ?? throw new ArgumentNullException(nameof(databaseCreator)); + _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(DocumentClient); + _databaseCreator = databaseCreator ?? new CosmosDatabaseCreator(DocumentClient); _cosmosScaler = new CosmosScaler(this); InitialiseCosmosStore(); } internal CosmosStore(IDocumentClient documentClient, string databaseName, - IDatabaseCreator databaseCreator, - ICollectionCreator collectionCreator, + IDatabaseCreator databaseCreator = null, + ICollectionCreator collectionCreator = null, bool scaleable = false) { DocumentClient = documentClient ?? throw new ArgumentNullException(nameof(documentClient)); Settings = new CosmosStoreSettings(databaseName, documentClient.ServiceEndpoint, documentClient.AuthKey.ToString(), documentClient.ConnectionPolicy, scaleCollectionRUsAutomatically: scaleable); if (string.IsNullOrEmpty(Settings.DatabaseName)) throw new ArgumentNullException(nameof(Settings.DatabaseName)); - _databaseCreator = databaseCreator ?? throw new ArgumentNullException(nameof(databaseCreator)); - _collectionCreator = collectionCreator ?? throw new ArgumentNullException(nameof(collectionCreator)); + _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(DocumentClient); + _databaseCreator = databaseCreator ?? new CosmosDatabaseCreator(DocumentClient); _cosmosScaler = new CosmosScaler(this); InitialiseCosmosStore(); } diff --git a/Cosmonaut/Extensions/CosmonautServiceCollectionExtensions.cs b/Cosmonaut/Extensions/CosmonautServiceCollectionExtensions.cs index 9bab275..737aeea 100644 --- a/Cosmonaut/Extensions/CosmonautServiceCollectionExtensions.cs +++ b/Cosmonaut/Extensions/CosmonautServiceCollectionExtensions.cs @@ -9,10 +9,7 @@ public static class CosmonautServiceCollectionExtensions { public static IServiceCollection AddCosmosStore(this IServiceCollection services, CosmosStoreSettings settings) where TEntity : class { - var documentClient = DocumentClientFactory.CreateDocumentClient(settings); - services.AddSingleton>(x=> new CosmosStore(settings, - new CosmosDatabaseCreator(documentClient), - new CosmosCollectionCreator(documentClient))); + services.AddSingleton>(x=> new CosmosStore(settings)); return services; } @@ -26,8 +23,8 @@ public static IServiceCollection AddCosmosStore(this IServiceCollection public static IServiceCollection AddCosmosStore(this IServiceCollection services, IDocumentClient documentClient, string databaseName, - IDatabaseCreator databaseCreator, - ICollectionCreator collectionCreator) where TEntity : class + IDatabaseCreator databaseCreator = null, + ICollectionCreator collectionCreator = null) where TEntity : class { services.AddSingleton>(x => new CosmosStore(documentClient, databaseName, databaseCreator, collectionCreator)); return services; From 9bdaf1aeab05a423b2073d302410239fbd8dc119 Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Thu, 10 May 2018 21:41:26 +0100 Subject: [PATCH 2/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 70f4c15..d791479 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Registering the CosmosStores in ServiceCollection for DI support "<>"); serviceCollection.AddCosmosStore(cosmosSettings); +//or just initialise it +ICosmosStore bookStore = new CosmosStore(cosmosSettings) ``` ##### Quering for entities From ddbfd0cd0f3393e46445b388f9f902231453cebc Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Fri, 11 May 2018 16:38:31 +0100 Subject: [PATCH 3/8] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d791479..ba2dafe 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ It is HIGHLY recommended that you use one of the `Async` methods to get the resu var user = await cosmoStore.Query().FirstOrDefaultAsync(x => x.Username == "elfocrash"); var users = await cosmoStore.Query().ToListAsync(x => x.HairColor == HairColor.Black); var otherUsers = await cosmosStore.Query().Where(x => x.Name.StartsWith("Smit")).ToListAsync(cancellationToken) + +// or you can use SQL + +var user = await cosmoStore.QueryMultipleAsync("select * from c w.Firstname = 'Smith'"); ``` ##### Adding an entity in the entity store From 6e17942c4da3fe31d2a827050134b1b8d784bd7a Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Sat, 12 May 2018 19:44:49 +0100 Subject: [PATCH 4/8] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba2dafe..f95d341 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,18 @@ Registering the CosmosStores in ServiceCollection for DI support "<>"); serviceCollection.AddCosmosStore(cosmosSettings); -//or just initialise it + +//or just by using the Action extension + +serviceCollection.AddCosmosStore(options => + { + options.DatabaseName = "<>"; + options.AuthKey = "<>"; + options.EndpointUrl = new Uri("<>"); + }); + +//or just initialise the object + ICosmosStore bookStore = new CosmosStore(cosmosSettings) ``` From 0deeebad14a127625722a8410e5c43e7737b6296 Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Sun, 13 May 2018 17:06:57 +0100 Subject: [PATCH 5/8] Downgrades DocumentDB.Core to 1.9.1, because MS unpublished 1.10.0 --- Cosmonaut/Cosmonaut.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cosmonaut/Cosmonaut.csproj b/Cosmonaut/Cosmonaut.csproj index 28c2235..b21838d 100644 --- a/Cosmonaut/Cosmonaut.csproj +++ b/Cosmonaut/Cosmonaut.csproj @@ -12,7 +12,7 @@ https://github.com/Elfocrash/Cosmonaut cosmosdb azure cosmos entitystore entity db orm Please report any issues on Github. - 1.4.0 + 1.4.2 @@ -26,7 +26,7 @@ - + From cf8c032eea2ae8fd3e2359205086c29f5f5845b8 Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Sun, 13 May 2018 17:10:12 +0100 Subject: [PATCH 6/8] Oopsie --- Cosmonaut.Tests/MockHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cosmonaut.Tests/MockHelpers.cs b/Cosmonaut.Tests/MockHelpers.cs index c326457..92f4922 100644 --- a/Cosmonaut.Tests/MockHelpers.cs +++ b/Cosmonaut.Tests/MockHelpers.cs @@ -59,7 +59,7 @@ public static Mock GetMockDocumentCollection() { resource.SetResourceTimestamp(DateTime.UtcNow); var resourceResponse = new ResourceResponse(resource); - var documentServiceResponseType = Type.GetType("Microsoft.Azure.Documents.DocumentServiceResponse, Microsoft.Azure.DocumentDB.Core, Version=1.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + var documentServiceResponseType = Type.GetType("Microsoft.Azure.Documents.DocumentServiceResponse, Microsoft.Azure.DocumentDB.Core, Version=1.9.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); var flags = BindingFlags.NonPublic | BindingFlags.Instance; From f639760b115a30bb91a3ef2a3448f35057824b01 Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Mon, 14 May 2018 00:24:15 +0100 Subject: [PATCH 7/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f95d341..5955839 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ ICosmosStore bookStore = new CosmosStore(cosmosSettings) ##### Quering for entities In order to query for entities all you have to do is call the `.Query()` method and then use LINQ to create the query you want. -It is HIGHLY recommended that you use one of the `Async` methods to get the results back, such as `ToListAsync` or `FirstOrDefaultAsync` , when available. +It is HIGHLY recommended that you use one of the `Async` extensions methods to get the results back, such as `ToListAsync` or `FirstOrDefaultAsync` , when available. ```csharp var user = await cosmoStore.Query().FirstOrDefaultAsync(x => x.Username == "elfocrash"); From a30b186b4bd2644290e58d503a522e74d366c9d3 Mon Sep 17 00:00:00 2001 From: Nick Chapsas Date: Mon, 14 May 2018 00:24:39 +0100 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5955839..5b8cedc 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ ICosmosStore bookStore = new CosmosStore(cosmosSettings) ##### Quering for entities In order to query for entities all you have to do is call the `.Query()` method and then use LINQ to create the query you want. -It is HIGHLY recommended that you use one of the `Async` extensions methods to get the results back, such as `ToListAsync` or `FirstOrDefaultAsync` , when available. +It is HIGHLY recommended that you use one of the `Async` extension methods to get the results back, such as `ToListAsync` or `FirstOrDefaultAsync` , when available. ```csharp var user = await cosmoStore.Query().FirstOrDefaultAsync(x => x.Username == "elfocrash");