dazinator / Dotnettency

Mutlitenancy for dotnet applications
MIT License
111 stars 23 forks source link

EF Core - reset lazy tenant id #36

Closed dazinator closed 5 years ago

dazinator commented 6 years ago

Add ability to reset the Lazy tenantId on the MultiTenantDbContext. Just in case in scenarios like testing or xamarin apps, where you want to re-use the same dbcontext instance, but a user logs in or logs out. In that case you could tell the dbcontext to invalidate its lazily cached tenant id - so it will request it again - and you can return the newly logged in user id.

You would call a method like this on the MultiTenantDbContext


        protected void OnTenantChanged()
        {
           // reset the lazy tenant id.
            _tenantId = new Lazy<TIdType>(() =>
            {
                var t = _tenant();
                return GetTenantId(t);
            });
        }
dazinator commented 5 years ago

Take into account that filters don't stack https://github.com/aspnet/EntityFramework.Docs/issues/768

dazinator commented 5 years ago

Dont need this for now.