Open Closed

Tenant extra properties in Config State Service #8390


User avatar
0
stephanobalbinot created

Check the docs before asking a question: https://abp.io/docs/latest Check the samples to see the basic tasks: https://abp.io/docs/latest/samples The exact solution to your question may have been answered before, and please first use the search on the homepage. Provide us with the following info: 🧐 Hint: If you are using the ABP Studio, you can see all the information about your solution from the configuration window, which opens when you right-click on the solution and click on the Solution Configuration button.

  • ABP Framework version: v9.0.0
  • UI Type: Angular
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hello,

I added two extra columns to my Tenant entity and I need to make them available in angular through Config State Service (currentTenant property). How could I do this? What's the best approach?

ObjectExtensionManager.Instance.Modules()
    .ConfigureSaas(saas =>
    {
        saas.ConfigureTenant(tenant =>
        {
            tenant.AddOrUpdateProperty<int>(
                "MunicipioId",
                property =>
                {
                    property.UI.Lookup.Url = "/api/app/cidadaos/lookup/municipios";
                    property.UI.Lookup.DisplayPropertyName = "displayName";
                    //property.Attributes.Add(new RequiredAttribute());
                    //property.Attributes.Add(new LengthAttribute(minimumLength: 7, maximumLength: 7));
                }
            );
        });
    });
}
OneTimeRunner.Run(() =>
{
    ObjectExtensionManager.Instance
        .MapEfCoreProperty<Tenant, int>(
            "MunicipioId",
            (entityBuilder, propertyBuilder) =>
            {
                propertyBuilder.HasMaxLength(7);
                propertyBuilder.IsRequired();
            }
        );

    ObjectExtensionManager.Instance
        .MapEfCoreProperty<Tenant, string>(
            "MunicipioId_Text",
            (entityBuilder, propertyBuilder) =>
            {
                propertyBuilder.HasMaxLength(255);
                propertyBuilder.IsRequired();
                propertyBuilder.HasColumnName("Municipio");
            }
        );
});

Thanks!


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can't add them to currentTenant property, but you can add them to the extraProperties

    for example

    public class CurrentTenantExtension
    {
        public Guid MunicipioId { get; set; }
    }
    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(AbpApplicationConfigurationController))]
    public class MyAbpApplicationConfigurationController : AbpApplicationConfigurationController
    {
        public MyAbpApplicationConfigurationController(IAbpApplicationConfigurationAppService applicationConfigurationAppService, IAbpAntiForgeryManager antiForgeryManager) : base(applicationConfigurationAppService, antiForgeryManager)
        {
        }
    
        public override async Task<ApplicationConfigurationDto> GetAsync(ApplicationConfigurationRequestOptions options)
        {
            var result =await base.GetAsync(options);
            var tenantExtension = new CurrentTenantExtension();
            {
                tenantExtension.MunicipioId = Guid.NewGuid(); // test
            }
            result.SetProperty("currentTenantExtension", tenantExtension);
    
            return result;
        }
    }
    

  • User Avatar
    0
    stephanobalbinot created

    It worked, thank you!

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09