Open Closed

TenantId Null in the newly added Module #7747


User avatar
0
castcrewit created
  • ABP Framework version: Latest
  • UI Type: Angular
  • Database System: MySQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): Auth server Separete
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I am trying to test Multi-Tenancy in the new module i just created. I am able to get the token and I can see the __tenantId being passed in the header. I put a logger in the module to check the TenantId and its always coming null

public class SampleController : VendorManagementController, ISampleAppService
{
    private readonly ISampleAppService _sampleAppService;
    private readonly ILogger<SampleController> _logger;

    public SampleController(ISampleAppService sampleAppService, ILogger<SampleController> logger)
    {
        _sampleAppService = sampleAppService;
        _logger = logger;
    }

    [HttpGet]
    public async Task<SampleDto> GetAsync()
    {
        if (CurrentTenant.Id.HasValue)
            _logger.LogInformation("TenantId :" + CurrentTenant.Id);
        else
            _logger.LogInformation("TenantId is null");
        return await _sampleAppService.GetAsync();
    }

    [HttpGet]
    [Route("authorized1")]
    [Authorize]
    public async Task<SampleDto> GetAuthorizedAsync()
    {
        return await _sampleAppService.GetAsync();
    }
}

I also tried to use Swagger and no success Can you help me understand how I can get the TenantId properly, is there any settings I need to switch on or something


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

    Did you add the MultiTenancy middleware?

    app.UseMultiTenancy();

  • User Avatar
    0
    castcrewit created

    Where do I add this ? Should I add this in the Module or Micro Service ? Please provide a little more clearer instructions. I am coming from AspNetZero background but this is pretty new to me, so little bit more explanation is helpful. And when I added the the microservices I rememeber adding Multitenancy as true as that was the default selection

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    i don't know your project details,

    could you share a minimal reproducible project with me. i will check it.

    shiwei.liang@volosoft.com

  • User Avatar
    0
    castcrewit created

    I have sent the link to download the module and micro service

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    you should add UseMultiTenancy to PSLWebVendorServiceModule

    You can refer to another service.

  • User Avatar
    0
    castcrewit created

    I need some calrifications around the app.useMultiTenancy(). I tried with doing it as th Microservice level only and it didn't work and then I had to add it to the module level and then it started working. So the question is do we need to add MultiTenancy at the Module and microservice level.

    If not can you please explain whats the right way to go about it

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    you have to add it to the module level. since modules can be designed to be multi-tenant or not

Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13