Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Custom TenantId resolver fails to load #4604


User avatar
0
vladsd created

I have implemented custom resolver, catch all situation, resolves to default tenant id. See

//https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy
    public class DefaultTenantResolveContributor : ITenantResolveContributor, ITransientDependency
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private static int DEFAULT_TENANT = 3;

        public DefaultTenantResolveContributor(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }

        public int? ResolveTenantId()
        {
            return DEFAULT_TENANT;
        }
    }

It is added in PreInitialize in Core module

Configuration.MultiTenancy.Resolvers.Add<DefaultTenantResolveContributor>();

When application runs, it fails to load it. With exception:

Castle.MicroKernel.ComponentNotFoundException HResult=0x80131500 Message=No component for supporting the service DefaultTenantResolveContributor was found Source=Castle.Windsor StackTrace: at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) at Abp.Dependency.IocResolverExtensions.ResolveAsDisposable[T](IIocResolver iocResolver, Type type) at Abp.MultiTenancy.TenantResolver.GetTenantIdFromContributors() at Abp.MultiTenancy.TenantResolver.ResolveTenantId() at Abp.Runtime.Session.ClaimsAbpSession.get_TenantId() at Abp.Domain.Uow.UnitOfWorkBase.SetFilters(List1 filterOverrides) at Abp.Domain.Uow.UnitOfWorkBase.Begin(UnitOfWorkOptions options) at Abp.Domain.Uow.UnitOfWorkManager.Begin(UnitOfWorkOptions options) at MyProject.Migrations.Seed.SeedHelper.WithDbContext[TDbContext](IIocResolver iocResolver, Action1 contextAction) in C:\Dev\MyProject\Base\aspnet-core\src\MyProject.EntityFrameworkCore\Migrations\Seed\SeedHelper.cs:line 38 at MyProject.Migrations.Seed.SeedHelper.SeedHostDb(IIocResolver iocResolver) in C:\Dev\MyProject\Base\aspnet-core\src\MyProject.EntityFrameworkCore\Migrations\Seed\SeedHelper.cs:line 18 at MyProject.EntityFrameworkCore.MyProjectEntityFrameworkCoreModule.PostInitialize() in C:\Dev\MyProject\Base\aspnet-core\src\MyProject.EntityFrameworkCore\EntityFrameworkCore\MyProjectEntityFrameworkCoreModule.cs:line 51 at System.Collections.Generic.List1.ForEach(Action1 action) at Abp.AbpBootstrapper.Initialize()

Please help what I am missing as I followed the doc at <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy">https://aspnetboilerplate.com/Pages/Doc ... ti-Tenancy</a>

Thank you.


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @vladsd it seems like DefaultTenantResolveContributor is not registered to dependency injection. In which project have you created DefaultTenantResolveContributor ?

  • User Avatar
    0
    vladsd created

    It is created in my new project I call MyProject.Extensions

    I tried adding this code in core module but it did not help: Configuration.IocManager.IocContainer.Register( Component.For<ITenantResolveContributor>() .ImplementedBy<DefaultTenantResolveContributor>() .LifestyleTransient()); }

  • User Avatar
    0
    vladsd created

    Looks like a proper way to register is

    Configuration.IocManager.Register<ITenantResolveContributor, DefaultTenantResolveContributor>(DependencyLifeStyle.Transient);
    

    It worked.

  • User Avatar
    0
    alper created
    Support Team

    thanks for the feedback ;)