示例#1
1
        //<inheritdoc/>
        public IEnumerable<Tenant> GetEnabledTenants()
        { 
            var fileProvider = _hostingEnvironment.ContentRootFileProvider;

            var tenantFolders = fileProvider
                .GetDirectoryContents("tenants")
                .Where(info => info.IsDirectory);

            foreach (var tenantFolder in tenantFolders)
            {
                var tenantFileName = "tenant.json";
                var tenantDirectoryPath = Path.Combine("tenants", tenantFolder.Name);
                var tenantFilePath = Path.Combine(tenantDirectoryPath, tenantFileName);
                var tenantFileInfo = fileProvider.GetFileInfo(tenantFilePath);
                if (tenantFileInfo.Exists)
                {
                    var builder = new ConfigurationBuilder();
                    builder.SetFileProvider(fileProvider);
                    builder.AddJsonFile(tenantFilePath);
                    var config = builder.Build();

                    var tenant = new Tenant
                    {
                        TenantId = tenantFolder.Name,
                        Configuration = config,
                        Identities = config.GetSection("Identities").GetChildren().Select(t => t.Value),
                        Extensions = config.GetSection("Extensions").GetChildren().Select(t => t.Value),
                        Path = tenantFolder.PhysicalPath
                    };

                    yield return tenant;
                }
            }
        }