コード例 #1
0
        public static Task ClearDownTransientTenantContentStore(FeatureContext context)
        {
            return(context.RunAndStoreExceptionsAsync(async() =>
            {
                ITenant currentTenant = context.GetTransientTenant();

                if (currentTenant != null)
                {
                    IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(context);
                    ITenantCosmosContainerFactory containerFactory = serviceProvider.GetRequiredService <ITenantCosmosContainerFactory>();
                    CosmosContainerDefinition containerDefinition = serviceProvider.GetRequiredService <CosmosContainerDefinition>();
                    Container container = await containerFactory.GetContainerForTenantAsync(currentTenant, containerDefinition).ConfigureAwait(false);
                    await container.DeleteContainerAsync().ConfigureAwait(false);
                }
            }));
        }
        public static async Task SetupCosmosContainerForRootTenant(FeatureContext featureContext)
        {
            IServiceProvider serviceProvider      = ContainerBindings.GetServiceProvider(featureContext);
            ITenantCosmosContainerFactory factory = serviceProvider.GetRequiredService <ITenantCosmosContainerFactory>();
            ITenantProvider tenantProvider        = serviceProvider.GetRequiredService <ITenantProvider>();

            string containerBase = Guid.NewGuid().ToString();

            CosmosConfiguration config = tenantProvider.Root.GetDefaultCosmosConfiguration();

            config.DatabaseName          = "endjinspecssharedthroughput";
            config.DisableTenantIdPrefix = true;
            tenantProvider.Root.SetDefaultCosmosConfiguration(config);

            Container contentManagementSpecsContainer = await factory.GetContainerForTenantAsync(
                tenantProvider.Root,
                new CosmosContainerDefinition("endjinspecssharedthroughput", $"{containerBase}contentmanagementspecs", Content.PartitionKeyPath, databaseThroughput : 400)).ConfigureAwait(false);

            featureContext.Set(contentManagementSpecsContainer, ContentManagementSpecsContainer);
            featureContext.Set <IContentStore>(new CosmosContentStore(contentManagementSpecsContainer), ContentManagementSpecsContentStore);
        }