- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们目前正在将 Web 应用单租户转换为 Multi-Tenancy 。
我们希望根据 TenantId(从 header 、查询字符串或 RabbitMQ header 中检索)覆盖 appsettings.json 中包含的数据。
“租户识别”服务运作良好。我们得到了一个返回 TenantId
的 ITenantResolverService
。
目前,我们的 IOptions 被 appsettings.json
覆盖,然后是 appsettings.Development.json
,最后被环境变量覆盖。
public Startup(IHostingEnvironment environment)
{
var builder = new ConfigurationBuilder()
.SetBasePath(environment.ContentRootPath)
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{environment.EnvironmentName}.json", true)
.AddJsonFile("appsettings.local.json", true)
.AddJsonFile($"k8s-mount/appsettings.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
我们希望在 环境变量
之前添加一个基于 TenantId
的覆盖。例如:appsettings.tenantId.json
,有时来自 Vault 中的 JSON 文件。
我们应该从哪里开始?我们已经看到很多关于每个租户的“硬编码”值(value)的文章。 (例如:https://michael-mckenna.com/multi-tenant-asp-dot-net-core-application-tenant-specific-configuration-options)
但似乎没有什么能满足要求,
最佳答案
很抱歉没有早点到这里,但是这里是您可以尝试的。使用文件配置提供程序并将您的租户配置放在由租户命名的文件中。 ASP.NET 运行时将为您监视文件。最初构建此机制是为了使用每个配置值的文件,因此如果您想要配置对象,则必须反序列化它们。
这里是添加文件配置提供者的方法:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(confBuilder =>
{
confBuilder.SetBasePath(Directory.GetCurrentDirectory());
var path = Path.Combine(Directory.GetCurrentDirectory(), "tenant-configs");
confBuilder.AddKeyPerFile(path, true);
})
.UseStartup<Startup>();
您可以在这里找到完整的资源:https://github.com/MichaelSL/asp.net-multitenant-configs
关于c# - ASP.NET Core - 每个租户的 IOptions,每个租户或 Vault 的 appsetting.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57152075/
我可以将 IConfiguration 配置注入(inject)构造函数,然后通过 config["settignName"] 从 json 文件访问应用程序设置; 服务类中的示例代码: public
我已经实现了 IndexBuilderSettings,它是某些服务的模型,例如当我为其创建一个模型时,如下所示 services.AddSingleton() .Configure((set
我已经实现了 IndexBuilderSettings,它是某些服务的模型,例如当我为其创建一个模型时,如下所示 services.AddSingleton() .Configure((set
是否可以将 JSON 文件 (appsettings.json) 中的属性绑定(bind)到使用不同属性名称的类? { "WebTarget": { "WebURL": "http:/
在 ASP.NET Core 2.1 中,我有一个使用 IOptions 接口(interface)发送电子邮件的类,如下所示: public class Email { private re
在我的 .NET Core 项目中,我在 Configure 方法中有以下设置: public void ConfigureServices(IServiceCollection services)
我正在尝试在我创建的服务中注入(inject) IOptions,但它始终为 null: public class Startup { private IConfiguration confi
在我看来,让域服务需要 IOptions 的实例是个坏主意。传递它的配置。现在我必须将额外的(不必要的?)依赖项添加到库中。我见过很多注入(inject) IOptions 的例子遍布网络,但我看不到
我正在尝试创建一个使用 IOptions 的通用方法作为参数,但代码似乎无效。 Visual Studio 显示以下消息: TConfig must be a non-abstract type wi
我有一个 worker service ind dotnet core 3.1: 程序.cs: public class Program { public static voi
我正在使用我在实际应用程序中使用的相同 Autofac 模块注册编写集成测试。我使用这样的基类将其连接起来: public abstract class ContainerFixture where
我不明白!我发誓我严格按照文档 ( Options pattern in ASP.NET Core ) 进行操作,但是一旦我开始使用我的服务,选项值为 null。 这是 appsettings.jso
选项模式允许我创建包含配置值的选项对象,如下所述:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/op
我正在尝试在一个带有 NancyFX 的项目上实现选项模式(如推荐的 here )/TinyIOC但它不起作用。 我正在 Startup.cs.ConfigureServices 上注册选项方法,但是
我有一个从 ASP.Net Core(目标 4.5)和 4.5 网络应用程序引用的类库,我想共享应用程序设置。我在 4.5 端使用 Unity for DI,在 Core 端使用 Core Boots
我正在使用 IOptions<>根据 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options
我想让类保持静态。是否有任何解决方法来注入(inject) IOptions 不修改访问修饰符? public static class Encrypter { private static
我正在尝试为一个类(在 .net Core 项目中)编写一个 xunit 测试,它看起来像: public Class FoodStore:IFoodStore { FoodList food
我刚开始使用 net core 2.1 构建 API。 我在 appsettings.json 中添加了我的连接字符串,我想访问它。 appsettings.json "MySettings":
我试图在使用内置 DI 机制的同时获得与 ASP.NET Core 2.1 应用程序一致的 .NET Framework 类库。现在,我创建了一个配置类并将适当的部分添加到 appsettings.j
我是一名优秀的程序员,十分优秀!