我有两个微服务API
User
和
Order
. 因为这些都是微服务,所以它们都有
分离
dbContext和Different
无关的
实体。我的要求之一是列出
Orders
与
名字
的
用户
是谁命令的
这个
简化
实体如下:
public class User
{
public Guid UserId {get;set;}
public string Name {get;set;}
//Notice no ORM relations added for Order
}
public class Order
{
public Guid OrderId {get;set;}
public Guid UserId {get;set}
//Notice no ORM relations user added. ONLY UserId is returned since this is a microservice and another domain
}
现在,我只能想一个有效的方法,但仍然有它的缺点
检索订单并将所有用户ID发送给用户微服务,方法如下:
public ICollection<Tuple<Guid,string> GetUserNames(ICollection<Guid> userIds)
{
//go to the database with ORM and get userId and username as a list
}
使用我的方法,这似乎不现实,因为有一天,需求可能会改变,用户的性别或任何其他信息可能会被额外要求。然后,我必须为那个特定的需求编写许多方法,或者每次都要更改我的代码。
另外,检索
所有
信息的
user
每次都不实用,因为它会消耗大量的网络流量。
有没有比我想象中更好地处理共享实体的最佳实践?或者,您认为这种方法仍然足够好吗?
谢谢。