public DocumentDbRepository(IDocumentDbConfigurationOptions configuration) { var resources = DocumentDbResources.CreateResources(configuration); Client = resources.DocumentClient; DocumentCollection = resources.DocumentCollection; }
/// <summary> /// Creates new database, collection and document client if those required resources do not exist. /// </summary> /// <param name=configuration>The definition of required resources.</param> /// <param name=cancellationToken>The instance of a cancellation token.</param> /// <returns>A collection of created or retrieved resources.</returns> public static async Task <DocumentDbRepositoryResources> CreateResourcesAsync( IDocumentDbConfigurationOptions configuration, CancellationToken cancellationToken) { var client = new DocumentClient(configuration.DocumentDb, configuration.Key); var database = await DocumentDbUtil.GetOrAddDatabase(configuration.DatabaseName, client, cancellationToken); var documentCollection = await DocumentDbUtil.GetOrAddDocumentCollection( configuration.CollectionName, client, database, cancellationToken, configuration.Throughput, configuration.TimeToLive, id => CreateDocumentCollection(configuration)); var resources = new DocumentDbRepositoryResources { DocumentClient = client, DocumentDatabase = database, DocumentCollection = documentCollection }; return(resources); }