public static int?GetAppInstanceIdFromHeader(HttpContext httpContext, ImplementationResolverOptions options)
 {
     if (!httpContext.Request.Headers.TryGetValue("AppInstance", out var appInstanceHeaders) || appInstanceHeaders.Count == 0)
     {
         return(options?.DefaultAppInstanceId);
     }
     else if (appInstanceHeaders.Count > 1)
     {
         throw new Exception("The AppInstance header should be specified exactly once");
     }
     else if (int.TryParse(appInstanceHeaders.Single(), out var appInstanceId))
     {
         return(appInstanceId);
     }
     throw new Exception("The AppInstance header should be an integer");
 }
 public ImplementationResolver(ImplementationResolverOptions options)
 {
     _options = options;
 }
        public static async Task <ImplementationContainer> GetContainer(HttpContext httpContext, ImplementationResolverOptions options)
        {
            int?appInstanceId;

            if (options.AppInstanceExtractor != null)
            {
                appInstanceId = options.AppInstanceExtractor(httpContext);
            }
            else
            {
                appInstanceId = GetAppInstanceIdFromHeader(httpContext, options);
            }
            if (appInstanceId == null)
            {
                return(null);
            }
            var scopeFactory = options?.ServiceScopeFactory ?? httpContext.RequestServices.GetRequiredService <IServiceScopeFactory>();
            var task         = _implementations.GetOrAdd(appInstanceId.Value, id => new Lazy <Task <ImplementationContainer> >(() => CreateImplementation(id, scopeFactory)));

            return(await task.Value);
        }
 public BusinessReflectorResolver(ImplementationResolverOptions options)
 {
     _options = options;
 }
 public MetadataModelResolver(ImplementationResolverOptions options)
 {
     _options = options;
 }
示例#6
0
        public static async Task <ImplementationContainer> GetContainer(HttpContext httpContext, ImplementationResolverOptions options)
        {
            int appInstanceId;

            if (!httpContext.Request.Headers.TryGetValue("AppInstance", out var appInstanceHeaders) || appInstanceHeaders.Count == 0)
            {
                if (options?.DefaultAppInstanceId == null)
                {
                    return(null);
                }
                appInstanceId = options.DefaultAppInstanceId.Value;
            }
            else if (appInstanceHeaders.Count > 1)
            {
                throw new Exception("The AppInstance header should be specified exactly once");
            }
            else if (!int.TryParse(appInstanceHeaders.Single(), out appInstanceId))
            {
                throw new Exception("The AppInstance header should be an integer");
            }
            var task = _implementations.GetOrAdd(appInstanceId, id => new Lazy <Task <ImplementationContainer> >(() => CreateImplementation(id, httpContext)));

            return(await task.Value);
        }
示例#7
0
        public static void ConfigureServices(IServiceCollection services, IConfiguration configuration
                                             , Action <DbContextOptionsBuilder, string> efProviderSetup, ImplementationResolverOptions implementationResolverOptions = null)
        {
            var provider = configuration.GetSection("EfProvider").Get <string>();

            if (string.IsNullOrWhiteSpace(provider))
            {
                Console.WriteLine("Error: database provider is not set, the expected name is: EfProvider");
            }
            var connectionString = configuration.GetConnectionString("Metadata");

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                Console.WriteLine("Error: Metadata Connection string is not set, the expected name is: Metadata");
            }

            switch (provider)
            {
            case "MySql":
                services.AddDbContext <MetadataDbContext, MetadataDbContext_MySql>(
                    options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString),
                                                x => x.MigrationsAssembly(typeof(MetadataDbContext_MySql).Assembly.GetName().Name)
                                                .MigrationsHistoryTable(HistoryRepository.DefaultTableName.ToLowerInvariant())));
                break;

            case "SqlServer":
                services.AddDbContext <MetadataDbContext>(options => options.UseSqlServer(connectionString));
                break;

            case "PostgreSql":
            case "PostgreSQL":
                services.AddDbContext <MetadataDbContext, MetadataDbContext_PostgreSql>(options => options.UseNpgsql(connectionString,
                                                                                                                     x => x.MigrationsAssembly(typeof(MetadataDbContext_PostgreSql).Assembly.GetName().Name)));
                break;

            default:
                throw new NotImplementedException($"The provider {provider} is not implemented yet.");
            }

            services.AddMultitenancy <IImplementationsContainer, ImplementationResolver>();
            services.AddSingleton(implementationResolverOptions ?? new ImplementationResolverOptions {
            });
            services.AddScoped <EntityHelper, EntityHelper>();
            services.AddSingleton <IPermissionService, PermissionCache>();
            services.AddSingleton <IUsersService, UsersCache>();
            services.Configure <GlobalConfiguration>(configuration.GetSection(nameof(GlobalConfiguration)));
            var globaConfig = configuration.GetSection(nameof(GlobalConfiguration)).Get <GlobalConfiguration>();

            services.AddSingleton <IGlobalConfiguration>(globaConfig);
            LobToolsStartup.ConfigureServices(services, configuration, efProviderSetup, implementationResolverOptions?.DefaultAppInstanceId);
        }