Example #1
0
        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);
        }
Example #2
0
        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);
        }