Starts in:
1 DAY
22 HRS
33 MIN
47 SEC
Starts in:
1 D
22 H
33 M
47 S

Activities of "Mohammad"

Thanks for the Explaination and refund.

the using statement worked.

Why do I need to do the using for Unitofwork for the repository to work? can you explain? Is this a workaround or an actual solution?

I am getting the same error even after adding [UnitOfWork]

2021-08-23 16:01:08.732 +03:00 [WRN] System.ObjectDisposedException: Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'ClientManagementDbContext'.
   at Microsoft.EntityFrameworkCore.DbContext.CheckDisposed()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.get_ChangeTracker()
   at Microsoft.EntityFrameworkCore.Query.CompiledQueryCacheKeyGenerator.GenerateCacheKeyCore(Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.RelationalCompiledQueryCacheKeyGenerator.GenerateCacheKeyCore(Expression query, Boolean async)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal.NpgsqlCompiledQueryCacheKeyGenerator.GenerateCacheKey(Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, LambdaExpression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken)
   at Zenithr.Tenant.Shared.AccessTokenTenantResolver.GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext) in C:\websites\ZENITHR3.0\Zenithr.Shared.Tenant\AccessTokenTenantResolver.cs:line 43
   at Volo.Abp.AspNetCore.MultiTenancy.HttpTenantResolveContributorBase.ResolveFromHttpContextAsync(ITenantResolveContext context, HttpContext httpContext)
   at Volo.Abp.AspNetCore.MultiTenancy.HttpTenantResolveContributorBase.ResolveAsync(ITenantResolveContext context)

Hi

I am using it in Custom Tenant Resolver.

 public class AccessTokenTenantResolver : HttpTenantResolveContributorBase
    {
        public override string Name => "AccessToken";



        protected override async Task<string> GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext)
        {
           

            IClientCredentialRepository clientCredentialRepository = context.ServiceProvider.GetRequiredService<IClientCredentialRepository>();

            string accessCode = httpContext.Request.Headers["Authorization"];

            if (!string.IsNullOrEmpty(accessCode))
            {
                var token = accessCode.Split(" ")[1];
                var tokenHandler = new JwtSecurityTokenHandler();
                var tokens = tokenHandler.ReadJwtToken(token);
                var client_id = tokens.Claims.FirstOrDefault(x => x.Type == "client_id").Value;
                var scopes = tokens.Claims.FirstOrDefault(x => x.Type == "scope").Value;

                if (scopes.Contains("Scope"))
                {
                    var client = await clientCredentialRepository.SingleOrDefaultAsync(x => x.ClientId == client_id);

                    if (client == null)
                        return await Task.FromResult<string>(null);

                   
                    return await Task.FromResult(client.TenantId.Value.ToString());
                }
            }

            return await Task.FromResult("37fb7b60-0ba6-8109-70b1-a049e5f25575");
        }
    }

Hi Maliming

Its belonging to the customtenantresolver

Hello

I am getting this error when I try to resolve a repository using ServiceProvider.GetService in CustomTenantResolver

Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.

Thanks

So what would you suggest in my case for Seperate database per tenant?

  1. Should I inherit all entities with IMultiTenant? If I do this then I'll have to store the tenantid in each table? Which doesnt serve the purpose of having separate databases per tenant.

The entity inherits IMultiTenant which means it is multi-tenant, and will try to get the connection string of the tenant.

In v4.0 It was working without Inheriting IMultiTenant https://github.com/abpframework/abp/blob/rel-4.0/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs

I think its a change that has been made in the new version?

For 1 request it asks to resolve AbpPermissionManagement, AbpAuditLogging on the 2nd request it Asks to resolve only AbpAuditLogging for the same page request.

I think this is because the Permissions are cached. So we don't need read it from db for 2nd request.

So according the the code behaviour It should try to resolve connection string for ProductManagement and Intelligence. But it only tries to resolve ProductManagement.

It will only be triggered when Intelligence-related repositories are used and the _currentTenant.Id not be null.

Your entity also need IsMultiTenant

I am using Single database per tenant.

  1. Should My entities implement IMultitenant?

https://github.com/abpframework/abp/blob/c4e92a3431787b1a6727a615768a7a2906a9ba69/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs#L52

Showing 1 to 10 of 48 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06