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

UserManager vs UserAppService #4422


User avatar
0
zokho created

Hi, can somebody please let me know why the functions and business logic for User (and Role) has been divided into 2 different places (UserManager and UserAppService)? I can see that the UserAppService sometimes using the functions within the UserManager. I am trying to understand the reason behind it so I could fallow the same principle with my own entities. In all demo and sample projects I have seen so far, all the business logic is supposed to be within the AppServices classes.

Thanks,


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

    From the documentation on NLayer Architecture:

    Application Layer Application layer mainly includes Application Services that use domain layer and domain objects (Domain Services, Entities...) to perform requested application functionalities. It uses Data Transfer Objects to get data from and to return data to presentation or distributed service layer. It can also deal with Authorization, Caching, Audit Logging, Object Mapping, Session and so on...

    Domain Layer This is the main layer that implements our domain logic. It includes Entities, Value Objects, Domain Services to perform business/domain logic. It can also include Specifications and trigger Domain Events. It defines Repository Interfaces to read and persist entities from data source (generally a DBMS).

  • User Avatar
    0
    zokho created

    Hi Aaron, Thanks for your comment. Well, the problem is I can't distinguish the business logic and the requested application functionalities. For instance in the UserAppService>CreateUserAsync, almost all the business logic of creating a user is located in the method body itself rather than the UserManager in the Domain layer.

    thanks

  • User Avatar
    0
    alper created
    Support Team

    Write all your logic to Application Service. Whenever you need to use the same logic in different places like in different application services you should you a domain service to share the code.

  • User Avatar
    0
    tteoh created

    <cite>alper: </cite> Write all your logic to Application Service. Whenever you need to use the same logic in different places like in different application services you should you a domain service to share the code.

    Hi Alper,

    Write all your logic to Application Service. Whenever you need to use the same logic in different places like in different application services you should you a domain service to share the code.[/quote]

    Would it be a good practice to write the logics as Private functions within the Application Service, while keeping the actual AppService functions focusing on DTOs operations. Later stage, the same logics to be shared with other AppService, then a these Private functions can be easily ported to Domain Service.

    Personally, I prefer to have logics implemented at Domain layer; however, it is extra overhead if logics are only used by a single AppService.

    Are my perspectives above correct?

    Thanks. /Tommy