Open Closed

How to get connect IdentityDbContext in my .*EntityFrameworkCore project #2465


User avatar
0
mc86 created

Hello I want to get all the User Role Org entities from IdentityDbContext in my .*EntityFrameworkCore project How can I achieve that? thanks~ or are there User Role Org cache in Redis ?


28 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can use Repository to get entities.

    https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

    https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs

  • User Avatar
    0
    mc86 created

    IdentityUsers doesn't exist in the current dbcontext.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You cannot use identity-related dbcontext and repository in your repository methods, you can use them in domain or application services.

    
    var users = IdentityUserRepository.GetAll()
    
    var mailRecive = mailReciveRepository.GetAll()
    
    
    var foo = mailRecive.where(user.xxx)
    
  • User Avatar
    0
    mc86 created

    like this?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Yes, Something like this.

  • User Avatar
    0
    mc86 created

    I added the Volo.Abp.Identity.Domain to my application project. get error after call the method/ what do I miss?

    [oaservice_6dfbae7e-7]: [16:30:21 ERR] ---------- RemoteServiceErrorInfo ---------- [oaservice_6dfbae7e-7]: { [oaservice_6dfbae7e-7]: "code": null, [oaservice_6dfbae7e-7]: "message": "对不起,在处理你的请求期间,产生了一个服务器内部错误!", [oaservice_6dfbae7e-7]: "details": null, [oaservice_6dfbae7e-7]: "data": { [oaservice_6dfbae7e-7]: "ActivatorChain": "CP.OaService.Controllers.Mails.MailController -> CP.OaService.Mails.MailsAppService" [oaservice_6dfbae7e-7]: }, [oaservice_6dfbae7e-7]: "validationErrors": null [oaservice_6dfbae7e-7]: } [oaservice_6dfbae7e-7]: [oaservice_6dfbae7e-7]: [16:30:21 ERR] An exception was thrown while activating CP.OaService.Controllers.Mails.MailController -> CP.OaService.Mails.MailsAppService. [oaservice_6dfbae7e-7]: Autofac.Core.DependencyResolutionException: An exception was thrown while activating CP.OaService.Controllers.Mails.MailController -> CP.OaService.Mails.MailsAppService. [oaservice_6dfbae7e-7]: ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'CP.OaService.Mails.MailsAppService' can be invoked with the available services and parameters: [oaservice_6dfbae7e-7]: Cannot resolve parameter 'Volo.Abp.Identity.IIdentityUserRepository identityUserRepository' of constructor 'Void .ctor(CP.OaService.Mails.IMailRepository, Volo.Abp.Identity.IIdentityUserRepository)'. [oaservice_6dfbae7e-7]: at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable1 parameters) [oaservice_6dfbae7e-7]: at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) [oaservice_6dfbae7e-7]: at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action1 next) [oaservice_6dfbae7e-7]: at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_6dfbae7e-7]: at Autofac.Builder.RegistrationBuilder3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action1 next) [oaservice_6dfbae7e-7]: at Autofac.Extras.DynamicProxy.RegistrationExtensions.<>c__DisplayClass8_03.<EnableInterfaceInterceptors>b__1(ResolveRequestContext ctxt, Action1 next) [oaservice_6dfbae7e-7]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_6dfbae7e-7]: --- End of inner exception stack trace --- [oaservice_6dfbae7e-7]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_6dfbae7e-7]: at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_6dfbae7e-7]: at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_6dfbae7e-7]: at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) [oaservice_6dfbae7e-7]: at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request) [oaservice_6dfbae7e-7]: at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) [oaservice_6dfbae7e-7]: at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) [oaservice_6dfbae7e-7]: at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext) [oaservice_6dfbae7e-7]: at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext) [oaservice_6dfbae7e-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) [oaservice_6dfbae7e-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() [oaservice_6dfbae7e-7]: --- End of stack trace from previous location --- [oaservice_6dfbae7e-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    I added the Volo.Abp.Identity.Domain to my application project.

    You also need the Volo.Abp.Identity.EntityFrameworkCore module.

  • User Avatar
    0
    mc86 created

    have added the Volo.Abp.Identity.EntityFrameworkCore.dll but still, get the same error. do I need to add any code?

    [oaservice_a9a502b8-e]: [17:10:31 ERR] ---------- RemoteServiceErrorInfo ---------- [oaservice_a9a502b8-e]: { [oaservice_a9a502b8-e]: "code": null, [oaservice_a9a502b8-e]: "message": "对不起,在处理你的请求期间,产生了一个服务器内部错误!", [oaservice_a9a502b8-e]: "details": null, [oaservice_a9a502b8-e]: "data": { [oaservice_a9a502b8-e]: "ActivatorChain": "CP.OaService.Controllers.Mails.MailController -> CP.OaService.Mails.MailsAppService" [oaservice_a9a502b8-e]: }, [oaservice_a9a502b8-e]: "validationErrors": null [oaservice_a9a502b8-e]: } [oaservice_a9a502b8-e]: [oaservice_a9a502b8-e]: [17:10:31 ERR] An exception was thrown while activating CP.OaService.Controllers.Mails.MailController -> CP.OaService.Mails.MailsAppService. [oaservice_a9a502b8-e]: Autofac.Core.DependencyResolutionException: An exception was thrown while activating CP.OaService.Controllers.Mails.MailController -> CP.OaService.Mails.MailsAppService. [oaservice_a9a502b8-e]: ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'CP.OaService.Mails.MailsAppService' can be invoked with the available services and parameters: [oaservice_a9a502b8-e]: Cannot resolve parameter 'Volo.Abp.Identity.IIdentityUserRepository identityUserRepository' of constructor 'Void .ctor(CP.OaService.Mails.IMailRepository, Volo.Abp.Identity.IIdentityUserRepository)'. [oaservice_a9a502b8-e]: at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable1 parameters) [oaservice_a9a502b8-e]: at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) [oaservice_a9a502b8-e]: at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Builder.RegistrationBuilder3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Extras.DynamicProxy.RegistrationExtensions.<>c__DisplayClass8_03.<EnableInterfaceInterceptors>b__1(ResolveRequestContext ctxt, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_a9a502b8-e]: --- End of inner exception stack trace --- [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request) [oaservice_a9a502b8-e]: at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) [oaservice_a9a502b8-e]: at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) [oaservice_a9a502b8-e]: at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext) [oaservice_a9a502b8-e]: at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext) [oaservice_a9a502b8-e]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) [oaservice_a9a502b8-e]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() [oaservice_a9a502b8-e]: --- End of stack trace from previous location --- [oaservice_a9a502b8-e]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Add them to your module depends on attribute.

    [DependsOn( typeof(AbpIdentityDomainModule), typeof(AbpIdentityEntityFrameworkCoreModule))]

  • User Avatar
    0
    mc86 created

    AFTER ADDED

    [DependsOn(
    typeof(AbpIdentityDomainModule),
    typeof(AbpIdentityEntityFrameworkCoreModule))]
    

    Got those errors

    No configuration found for Microsoft.EntityFrameworkCore.DbContext,

  • User Avatar
    0
    mc86 created

    [17:25:56 ERR] An exception was thrown while activating Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext -> λ:Microsoft.EntityFrameworkCore.DbContextOptions1[[Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext, Volo.Abp.Identity.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null]]. [oaservice_a9a502b8-e]: Autofac.Core.DependencyResolutionException: An exception was thrown while activating Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext -> λ:Microsoft.EntityFrameworkCore.DbContextOptions1[[Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext, Volo.Abp.Identity.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null]]. [oaservice_a9a502b8-e]: ---> Volo.Abp.AbpException: No configuration found for Microsoft.EntityFrameworkCore.DbContext, Microsoft.EntityFrameworkCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60! Use services.Configure<AbpDbContextOptions>(...) to configure it. [oaservice_a9a502b8-e]: at Volo.Abp.EntityFrameworkCore.DependencyInjection.DbContextOptionsFactory.Configure[TDbContext](AbpDbContextOptions options, AbpDbContextConfigurationContext1 context) [oaservice_a9a502b8-e]: at Volo.Abp.EntityFrameworkCore.DependencyInjection.DbContextOptionsFactory.Create[TDbContext](IServiceProvider serviceProvider) [oaservice_a9a502b8-e]: at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) [oaservice_a9a502b8-e]: at Autofac.Core.Activators.Delegate.DelegateActivator.<ConfigurePipeline>b__2_0(ResolveRequestContext ctxt, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) [oaservice_a9a502b8-e]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next) [oaservice_a9a502b8-e]: --- End of inner exception stack trace ---

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you share a private repository on Github? and invite me to the contributor. @maliming

  • User Avatar
    0
    mc86 created

    already added tks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You're using the microservice project, You can't add identity to your microservices.

    See Communications Between Microservices

    https://docs.abp.io/en/commercial/latest/startup-templates/microservice/interservice-communication

  • User Avatar
    0
    mc86 created

    Can I ADD [repalcedbcontext(identitydbcontext)] to my .*EntityFrameworkCore project to use the identitydbcontext?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    no

    You can use it in CP.IdentityService project.

  • User Avatar
    0
    mc86 created

    no

    You can use it in CP.IdentityService project.

    as you mentioned if I can't use identitydbcontext in my .*EntityFrameworkCore project, so the Identityuser navigation property can't use in my entities of the microservice solution?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Yes

  • User Avatar
    0
    mc86 created

    It worked in CP.IdentityService I got data from DB but after put the DB in cache , every data is incorrect what do I miss?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    The List<PORItem> needs to support serialization by JSON.

  • User Avatar
    0
    mc86 created

    https://docs.abp.io/en/abp/latest/Caching I see the IDistributedCache internally serializes/deserializes the cached objects in the doc.

    I tested

    string json = JsonConvert.SerializeObject(List<PORItem>); is worked fine.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can test your caching methods individually.

  • User Avatar
    0
    mc86 created

    Hi maliming The problem is not caused by caching . The method get correct data but after I call it from swagger, I just got " [{},{},{}]" what do I miss?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Please use DTO to replace the Entity type.

    https://docs.abp.io/en/abp/latest/Data-Transfer-Objects

  • User Avatar
    0
    mc86 created

    HI maliming

    still the same.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09