Exemplo n.º 1
0
 private static ServiceDescriptor BuildConventionMultitenantBasedStartup <TTenant>(Type startupType, MultiTenancyConfig <TTenant> multitenancyConfig)
     where TTenant : class => new ServiceDescriptor(
     typeof(IStartup),
     (IServiceProvider provider) =>
 {
     IHostingEnvironment hostingEnvironment      = provider.GetRequiredService <IHostingEnvironment>();
     StartupMethodsMultitenant <TTenant> methods = StartupLoaderMultitenant.LoadMethods <TTenant>(provider, startupType, hostingEnvironment.EnvironmentName);
     return(new ConventionMultitenantBasedStartup <TTenant>(methods, multitenancyConfig.BuildTenantLogProvider()));
 }, lifetime: ServiceLifetime.Singleton);
Exemplo n.º 2
0
        public void ConventionalStartupClass_WhenHasMulitpleOverrideConfigurePerTenantServicesWitouthEnv_ThrowsIfStartupBuildsTheContainerAsync()
        {
            // Arrange
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <IServiceCollection>, DefaultServiceProviderFactory>();
            ServiceProvider services = serviceCollection.BuildServiceProvider();

            // Act
            InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() =>
            {
                StartupMethodsMultitenant <TestTenant> startup = StartupLoaderMultitenant.
                                                                 LoadMethods <TestTenant>(services, typeof(TestStartupMulitpleOverrideConfigurePerTenantServicesWithoutEnv), string.Empty);
            });

            // Assert
            string expectedMessage = $"Having multiple overloads of method 'ConfigurePerTenantServices' is not supported.";

            Assert.Equal(expectedMessage, exception.Message);
        }