Mike Anderson
Mike Anderson

Reputation: 768

Create an aggregate object RESTfully

I haw an aggregate in my domain that have some Guid secondary keys.I want to get more info about these keys from another domains via RESTfull.

public class ProductAggregate
    {
        public Guid Id { get; set; }
        public Guid UserId { get; set; }
        public Guid AgencyId { get; set; }
        public string AgencyTitle { get; set; }
}

In above code the AgencyTitle not exists in current domain and I want to get it from another live service via Restfull and send aggregated object to the client. Is it a acceptable way?

Upvotes: 0

Views: 710

Answers (1)

tomliversidge
tomliversidge

Reputation: 2369

It sounds like you are talking about a read model that you present to a user rather than an aggregate.

There are various ways you can handle this:

Local Caching

Keep an in-memory cache locally in your service that maps between AgencyId and AgencyTitle - this can either be through:

  • listening to an event (i.e. AgencyCreated). This would be preferred if you are have an event-driven system. You could also listen to other events (i.e. AgencyTitleUpdated) if relevant.
  • by making a web request to the external services. You would query your local cache first, and then decide if to call the external service. You'd need to think about how stale you allow your cache to become.

Denormalising the data

You could duplicate the data by saving the AgencyTitle alongside the AgencyId. This way you have no call to an external service. The tradeoff is you need to consider how often the AgencyTitle is likely to change, and how you handle that change.

Reporting "domain"

You could have a completely separate service that listens for data from other services and maintains view models for UIs. This would keep your other services ignorant of other service's concerns. When using an event-driven system, you'd be listening for events form other services that allow you to build a view model for the UI

Upvotes: 5

Related Questions