设置租户设置

时间:2018-01-03 13:55:03

标签: c# settings multi-tenant aspnetboilerplate

我正在处理多租户应用程序,我的应用程序设置为Currency

public class MyAppSettingProvider : SettingProvider
{
    public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
    {
        return new[]
        {
            new SettingDefinition(MyAppSettingDefinition.Currency, string.Empty, scopes: SettingScopes.Tenant, isVisibleToClients: true),
        };
    }
}

public static class MyAppSettingDefinition
{
    public const string Currency = "MyApp.UserManagement.Currency";
}

我已将其添加到PreInitialize()方法中,如下所示。

Configuration.Settings.Providers.Add<MyAppSettingProvider>();

我的问题

现在,此设置仅为默认租户创建条目,并且没有其他租户的条目。

所以,我的问题是:

  • 如何设置租户特定设置?

  • 是否会在租户创建时间?如果是,那么我可以再次使用MyAppSettingProvider课吗?

  • 如果我删除默认租户可以吗?因为主机没有租户ID,并且我有固定数量的租户,其中不需要默认。

指导我,还支持样板架构的最佳实践 ..

1 个答案:

答案 0 :(得分:1)

  

如何设置租户特定设置?

注入ISettingManager并执行:

_settingManager.ChangeSettingForTenantAsync(tenantId, MyAppSettingDefinition.Currency, "$");
  

是否会在租户创建时间?如果是,那么我可以再次使用MyAppSettingProvider类吗?

不会自动创建设置。您可以使用TenantAppService MyAppSettingProvider方法进行配置。 您可以(但不应该)使用ISettingManagermy @aSortOrder = ( 'DELTA1_2', 'SET1', 'SET2' ); 是你想要的。

  

如果我删除默认租户可以吗?因为主机没有租户ID,我有固定数量的租户,其中不需要默认。

是。它是为了方便和演示而由模板创建的。

  

什么是最佳实践,也支持样板架构..

阅读Create上的文档。