public static IServiceCollection AddCosmosStore <TEntity>(this IServiceCollection services,
                                                                  string databaseName, Uri endpointUri, string authKey, Action <CosmosStoreSettings> settingsAction = null,
                                                                  string overriddenCollectionName = "") where TEntity : class
        {
            var settings = new CosmosStoreSettings(databaseName, endpointUri, authKey);

            settingsAction?.Invoke(settings);
            return(services.AddCosmosStore <TEntity>(settings, overriddenCollectionName));
        }
예제 #2
0
        public CosmosStore(CosmosStoreSettings settings, string overriddenCollectionName)
        {
            Settings     = settings ?? throw new ArgumentNullException(nameof(settings));
            DatabaseName = settings.DatabaseName;
            var documentClient = DocumentClientFactory.CreateDocumentClient(settings);

            CosmosClient = new CosmosClient(documentClient, Settings.InfiniteRetries);
            if (string.IsNullOrEmpty(Settings.DatabaseName))
            {
                throw new ArgumentNullException(nameof(Settings.DatabaseName));
            }
            _collectionCreator = new CosmosCollectionCreator(CosmosClient);
            _databaseCreator   = new CosmosDatabaseCreator(CosmosClient);
            InitialiseCosmosStore(overriddenCollectionName);
        }
예제 #3
0
 private CosmosStore(ICosmosClient cosmosClient,
                     string databaseName,
                     string overriddenCollectionName,
                     IDatabaseCreator databaseCreator     = null,
                     ICollectionCreator collectionCreator = null)
 {
     DatabaseName = databaseName;
     CosmosClient = cosmosClient ?? throw new ArgumentNullException(nameof(cosmosClient));
     Settings     = new CosmosStoreSettings(databaseName, cosmosClient.DocumentClient.ServiceEndpoint.ToString(), string.Empty, cosmosClient.DocumentClient.ConnectionPolicy);
     if (Settings.InfiniteRetries)
     {
         CosmosClient.DocumentClient.SetupInfiniteRetries();
     }
     if (string.IsNullOrEmpty(Settings.DatabaseName))
     {
         throw new ArgumentNullException(nameof(Settings.DatabaseName));
     }
     _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(CosmosClient);
     _databaseCreator   = databaseCreator ?? new CosmosDatabaseCreator(CosmosClient);
     InitialiseCosmosStore(overriddenCollectionName);
 }
 public static IServiceCollection AddCosmosStore <TEntity>(this IServiceCollection services,
                                                           CosmosStoreSettings settings, string overriddenCollectionName = "") where TEntity : class
 {
     services.AddSingleton <ICosmosStore <TEntity> >(x => new CosmosStore <TEntity>(settings, overriddenCollectionName));
     return(services);
 }
예제 #5
0
 public CosmosStore(CosmosStoreSettings settings) : this(settings, string.Empty)
 {
 }