Abp: How to get entity in Web Project.

Created on 27 Nov 2018  路  5Comments  路  Source: abpframework/abp

image

If we define the dependencies between modules as shown above,
How to use entities in web projects (because web projects don't depend on domains)
Such as private readonly SignInManager<MyEntity> _signInManager;
https://github.com/abpframework/abp/blob/b05751d2d0d45273a66baf7f48be8428ee636dd4/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs#L7-L20

question

All 5 comments

Domain has Entities that are most of the time 1:1 to database tables.
Application layer (Application.Contracts) holds DTO Objects that are mapped from Entities. (Mapping is done in Application layer)
In HttpApi/Client/Web you have to use those DTO objects.
Example:

Domain
    MyEntity
Application.Contracts
    MyEntityDTO
Application
   Map MyEntity -> MyEntityDTO.
   Method inputs and outputs must be DTO objects
Web
   Use MyEntityDTO

Best practices

Entity is 1:1 from Database
EntityDTO is an object that represents only data that is needed for Client.
As per some examples:
User entity can contain passwords and some other private information that can't be exposed, that's why we create DTO's User DTO won't have Password field so that our software would not expose passwords to other clients.
Sometimes you need to precalculate more info in a DTO then you can get from Entity, so in that case DTO would have more properties then Entity.
Most of the time DTO's are equivalent to Entities, that's why it might seem that making Entity 1:1 DTO is tedious and exposing Entity itself would be enough, but to ensure security and coupling you need to do DTO's.

@maliming we should not use entities in the web layer. Otherwise, we can't deploy we layer and application layer into separated servers. Web layer uses the application layer via app service interfaces and DTOs.

Account module is an exception. We haven't find a way of separating it because Microsoft's implementation forces to use UserManager, RoleManager and entities inside the web layer. We will work on that later if we can a way of it.

@SlowLogicBoy

thank you for your reply.

I read the documentation and just got confused.
As you can see, the above web project SignInManager<IdentityUser> uses the IdentityUser entity.

thanks @hikalkan

You're welcome :)

Was this page helpful?
0 / 5 - 0 ratings