Base solution for your next web application
Open Closed

Cannot SetTenantId(null) #1393


User avatar
0
arslanali created

hi there, I know its a very basic question, however your help will be appreciated following is my code

[UnitOfWork]
public async Task<string> GetPictureById(Guid? Id, int fWidth, int fHeight)
{            
    using (CurrentUnitOfWork.SetTenantId(null))
    {
        if (Id.HasValue)
        {
            var file =await _binaryObjectManager.GetOrNullAsync(Id.Value);
            var filename = ImageResizer(file.Bytes, fWidth, fHeight, Id.Value);
            return filename;                    
        }
        else
        {
            return null;
        }
    }
            
}

Its in my MVC Controller Class. I even put [UnitOfWork] annotation on my method.

the code is breaking with null reference at using statement. I tried with UnitOfWorkManager.Current and even with _unitOfWorkManager.Current by dependency injection. though I know that by default it is available in controllers.


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Your method should be virtual (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocUowRestrictions">http://www.aspnetboilerplate.com/Pages/ ... strictions</a>)

  • User Avatar
    0
    arslanali created

    thanks hikalkan, you rock :) i knew there is a small silly mistake :$

    Can I take a few more moments of yours and ask a question about another issue I posted earlier, but still struggling to understand what to do about the public users?

    #1361

    Actually its a big decision to make, I think i have 3 options:

    • I can create a PublicUser Entity and create a complete login/register logic for it and manage the sessions. (which seems very complicated and time consuming)
    • I can create a Tenant with a specific ID and handle its features, settings, pages etc. (which is also complicated)
    • I can create a separate application for PublicUsers with login and session management using ASP Net Boilerplate or buy another ASPNETZero license and create a single tenancy app and share database.

    Please share your opinon. looking forward to your ideas. Arslan.