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

IRepository<AbpUserBase> fails to resolve for custom module #6916


User avatar
0
mightyit created

Hi

I am getting the following error during run-time when trying to invoke a method on ***AppService, which is contained in a separate, well-contained module that is separate from my generated solution modules.

The module consists of several sub-modules, with proper dependencies set up between them

I have also done the following in terms of module dependencies:

  • Added a module dependency from my module core to AbpZeroCommonModule
  • Added the required module dependencies from my base solution Web.Core solution to the custom modules. (All app services from the module runs successfully, except this specific one)

Can't create component '***AppService' as it has dependencies to be satisfied.

'***AppService' is waiting for the following dependencies:

  • Service 'Abp.Domain.Repositories.IRepository`2[[Abp.Authorization.Users.AbpUserBase, Abp.Zero.Common, Version=4.4.0.0, Culture=neutral, PublicKeyToken=null],[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.

Castle.MicroKernel.Handlers.HandlerException: Can't create component '***AppService' as it has dependencies to be satisfied.

'***AppService' is waiting for the following dependencies:

  • Service 'Abp.Domain.Repositories.IRepository`2[[Abp.Authorization.Users.AbpUserBase, Abp.Zero.Common, Version=4.4.0.0, Culture=neutral, PublicKeyToken=null],[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.

Here is the redacted code for the affected applicationservice:

Please help - what am I missing here?


6 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    It's IRepository<User, long>.

  • User Avatar
    0
    mightyit created

    Thanks for the feedback.

    This wil work as a temporary quickfix, but is wrong insofar as clean coding principles.

    1. Creates an explicit dependency on a concrete class
    2. Tightly couples my module to my base solution (The User class is generated as part of your base solution and inherits from AbpUserBase).

    I am trying to do custom / direct registration as per the official dependency injection documentation, but without success.

  • User Avatar
    0
    aaron created
    Support Team

    You are mistaken. All generic repositories use concrete classes. You can register IUserRepository similar to that documentation.

  • User Avatar
    0
    mightyit created

    I'm not mistaken. I know the generic repository pattern. I'm talking about clean coding (SOLID) practices.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mightyit

    If you are only going to get records from AbpUsers table, you can create an interface as @aaron suggested named IUserRepository and work with AbpUserBase class in that repository. In that way, you can't create or update user records.

    Second option would be moving User entity to a shared class library project and use it from your module and AspNet Zero app.

  • User Avatar
    0
    mightyit created

    Hi @ismcagdas

    I have implemented the temporary workaround but have came to the same conclusion as your second suggestion - that a shared library for authentication and authorization should be created. Perhaps something to consider for future versions of the boilerplate solution (if I may suggest)?