Reputation: 5355
The story behind:
I have added new field ConnectionString
into Tenant
class.
I have changed TenantCacheItem.CustomData
also, so new ConnectionString
is also available from cache.
I have created my own MyDbPerTenantConnectionStringResolver: DbPerTenantConnectionStringResolver
, so it contains new method to get "MyNewConnectionString"
. If it is host, then MyDbPerTenantConnectionStringResolver
throws exception.
Now I have to create my own repository (it is not EF repository, but custom repository). And this repository should take "MyNewConnectionString"
from Tenant
.
I know that Tenant
information is available from AbpSession
. But I do not understand how and when AbpSession
should be sent to MyRepository
.
Probably, I have to add IAbpSession
in MyRepository
constructor, but how to set it? Who sets AbpSession
and when AbpSession
actually gets value?
If I understand how this works in ASP.NET Boilerplate's DbContext
, I could recreate the same logic in my own repository.
Upvotes: 1
Views: 2624
Reputation: 43098
Probably, I have to add IAbpSession in MyRepository Constructor, but how to set it?
You can property-inject IAbpSession
:
public class MyRepository : ITransientDependency
{
public IAbpSession AbpSession { get; set; }
public MyRepository()
{
AbpSession = NullAbpSession.Instance;
}
}
Who sets AbpSession and when AbpSession actually gets value?
IAbpSession
is implemented as a singleton by ClaimsAbpSession
.
Its properties are getters. For example:
public override long? UserId
{
get
{
// ...
var userIdClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == AbpClaimTypes.UserId);
// ...
long userId;
if (!long.TryParse(userIdClaim.Value, out userId))
{
return null;
}
return userId;
}
}
Upvotes: 2