Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TenantedCosmosContentStoreFactory"/> class.
 /// </summary>
 /// <param name="tenantProvider">The <see cref="ITenantProvider"/> that will be used to retrieve Tenant info.</param>
 /// <param name="containerFactory">The <see cref="ITenantCosmosContainerFactory"/> that will be used to create
 /// underlying <see cref="Container"/> instances for the content stores.</param>
 /// <param name="containerDefinition">The <see cref="CosmosContainerDefinition"/> to use when creating tenanted
 /// <see cref="Container"/> instances.</param>
 public TenantedCosmosContentStoreFactory(
     ITenantProvider tenantProvider,
     ITenantCosmosContainerFactory containerFactory,
     CosmosContainerDefinition containerDefinition)
 {
     this.tenantProvider      = tenantProvider;
     this.containerFactory    = containerFactory;
     this.containerDefinition = containerDefinition;
 }
Ejemplo n.º 2
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);
        }