private static async Task <CosmosDBStore <T> > Initialise <T>(CosmosDBOptions options) where T : Entity, IAggregateRoot { var client = new CosmosClient(options.Uri, options.Key); var store = new CosmosDBStore <T>(client, options); try { var database = await InitializeDatabase(client, options.DatabaseName); var containerName = EntityPluralizer.GetPlural(typeof(T).Name); try { await InitializeContainer(database, containerName, "/userId"); } catch (RequestFailedException) { Log.Fatal($"Necessary CosmosDB container '{containerName}' does not exist and creation failed."); throw; } } catch (RequestFailedException) { Log.Fatal($"Necessary CosmosDB database '{options.DatabaseName}' does not exist and creation failed."); throw; } return(store); }
public CosmosDBStore(CosmosClient client, CosmosDBOptions options) { // Get the type name and pluralize it var containerName = EntityPluralizer.GetPlural(typeof(T).Name); _container = client.GetContainer(options.DatabaseName, containerName); }
private static bool ValidateOptions(CosmosDBOptions options) { if (options == null) { return(false); } if (string.IsNullOrWhiteSpace(options.DatabaseName) || string.IsNullOrWhiteSpace(options.Key) || string.IsNullOrWhiteSpace(options.Uri)) { return(false); } return(true); }