protected override async Task RunAsync(CancellationToken cancellationToken) { try { // init service fabric context ServiceFabricServiceContext.Set(Context); // initailize DocumentDb client factory var config = new DocumentDbConnectionConfig(); documentDbClientFactory = new DocumentDbClientFactory(config); // initilize the DOcument database & collection await UserCollectionInitializer.Initialize(documentDbClientFactory); await Task.CompletedTask; } catch (Exception ex) { LoggingContext.CreateLogger <DocumentDbDependency>() .LogError(ex, "Service exception in RunAsync"); } }
public static async Task Initialize(IDocumentDbClientFactory documentDbClientFactory) { DatabaseId = ConfigurationManager.AppSettings.GetRefValue <string>(DatabaseIdConfigName); CollectionId = ConfigurationManager.AppSettings.GetRefValue <string>(CollectionNameConfigName); IDocumentClient client = documentDbClientFactory.GetClient(); try { await client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(DatabaseId)); } catch (DocumentClientException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { await client.CreateDatabaseAsync(new Database { Id = DatabaseId }); } } try { await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId)); } catch (DocumentClientException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { var documentCollection = new DocumentCollection { Id = CollectionId, IndexingPolicy = CollectionIndexingPolicy, }; await client.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri(DatabaseId), documentCollection, CollectionRequestOptions); } } }
public DocumentDbViewModelRepository(IDocumentDbSettings settings, IDocumentDbClientFactory clientFactory, ILogger logger) { _settings = settings; _clientFactory = clientFactory; _logger = logger; }
protected DocumentDbRepository(IDocumentDbClientFactory documentDbInitializer, string partitionKey = null) { PartitionKey = partitionKey; Client = documentDbInitializer.GetClient(); }
public DocumentDbWritableViewModelRepository(IDocumentDbSettings settings, IDocumentDbClientFactory clientFactory, ILogger logger) : base(settings, clientFactory, logger) { }
protected QuerableDocumentDbRepository(IDocumentDbClientFactory documentDbInitializer, string partitionKey = null) : base(documentDbInitializer, partitionKey) { }
public UserRepository(IDocumentDbClientFactory documentDbInitializer) : base(documentDbInitializer, null) { }