Skip to content

How to get CreatedBy name at querying? #412

Answered by MichaelHochriegl
ANMSalman asked this question in Q&A
Discussion options

You must be logged in to vote

Did you look at the template provided here? There is a ICurrentUserService.cs. This is used in the SaveChangesAsync method in infrastructure, so that an entity that extends from AuditableEntity get's the current user assigned.

If you query an entity that is an AuditableEnity you also have access to the CreatedBy and/or LastModifiedBy prop and can use this to display the user that created/modified the entity.

Update: If you need the current user in any other command/query you can simply ask for an ICurrentUserService and for an IIdentityService using dependency injection and can access the user info with this.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@ANMSalman
Comment options

@MichaelHochriegl
Comment options

@ANMSalman
Comment options

@ali-gol
Comment options

@MichaelHochriegl
Comment options

Answer selected by ANMSalman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants