Open Closed

Lookup user / Create user from microservice #2787


User avatar
0
chris.tune@gmail.com created

Hi

This is more of a design question, and I was hoping there would be some sample code?

**1. How should you look up a user in a microservice? **

For example, I want to choose a user from a list

or

I want to check some aspects of a user's details in an app service.

Currently we have a local table with users, which is synchronized through ETOs (e.g. EntityCreatedEto) We then use this local repository for our queries.

I noticed there is a UserLookupService that is used in CMS kit, but I can't seem to get this working in a microservice.

I'm not sure of the best approach.

**2. How should we add users from a microservice? **

For example, in a workflow microservice, the user has entered an email of someone to assign a task,

This user is not in the system yet so we want to invite/create user I'm assuming this is a standard inter-service communication to the identity service?


1 Answer(s)
  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    1. How should you look up a user in a microservice? For example, I want to choose a user from a list or I want to check some aspects of a user's details in an app service. Currently we have a local table with users, which is synchronized through ETOs (e.g. EntityCreatedEto) We then use this local repository for our queries. I noticed there is a UserLookupService that is used in CMS kit, but I can't seem to get this working in a microservice. I'm not sure of the best approach.

    You can use http requests to IdentityService to get the user list (UserLookupService). To do that; add IdentityService.Application.Contracts to your microservice application layer (or application.contracts) and add IdentityService.Http.Api.Client to your microservice http.host layer with RemoteService configuration on appsettings.

    2. How should we add users from a microservice? For example, in a workflow microservice, the user has entered an email of someone to assign a task, This user is not in the system yet so we want to invite/create user I'm assuming this is a standard inter-service communication to the identity service?

    This seems very subtle for async communication. You can publish an event from your microservice and let your custom handler you create on IdentityService handle it. You can inject IdentityUserManager (default Microsoft Identity library) and create a new user. Furthermore, you can even publish a new event after successful user creation and let some microservice or a background job send an email to the user informing about it.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19