English 中文(简体)
Domain Driven Design - External Data API as Respository or Service
原标题:

In a blog application developed using domain driven design a Post entity has a related collection of tag entities.

On creating the post (e.g populating the object from the UI) i would like to call a third party API via REST which takes the content of the post and extracts semantic tags (link text) for association.

Main Question : What is the best way to design this...

Is it best designed so that the Post entity would call a domain service such as PostServices.GetTags(Postcontent) passing its content and retrieving back a list of tags.?

** PostServices.GetTags would then inteface with the REST API via a further wrapper class.

Or should the third party API be wrapped as a repository?

Should the function Post.GenerateTags(), should not exist within the domain entity at all?

Further questions :

1 : I have also read that it is not good practice to have a domain entity converse with a domain service. Is this true?

2 : Is it ok to get a reference to the PostServices domain service via a factory creation method. e.g...

IPostService PostService = ServiceUtil.GetPostService(); return PostService.GetTags(Post.content);

3 : Is it acceptable to have the domain service coupled to a third party api?

4 : Should the domain entity simply just know how to deal with the tags received via the application layer which has called the REST API.

Slowly trying to get my head around DDD, however I can t seem to find any examples of how to implement this sort of thing.

问题回答

In a Blog application, a Post is an Entity and a Tag is a value object. A Tag hasn t got identity. You should have:

  • PostsRepository
  • Post (Entity)
  • Tag (value object)

A Post has got a list of tags.

Questions:

1 : I have also read that it is not good practice to have a domain entity converse with a domain service. Is this true?

Yes, itsn t a good practice. You entity hasn t want to be coupled with a domain service. If you do that, then you couldn t reuse them later. Did you have consider to fire a domain event. You can tell your service domain do something fire domain events.

2. : Is it ok to get a reference to the PostServices domain service via a factory creation method. e.g..IPostService PostService = ServiceUtil.GetPostService(); return PostService.GetTags(Post.content);

Yes, it s possible. A factory method could return an abstract class or an interface. This is a good Software Design Principle "code to an interface not to an implementation". If you do this, you ll be able to change your implementation later and you won t have to change yout client code.

3 : Is it acceptable to have the domain service coupled to a third party api?

I don t recommend you this, but it is acceptable.

Sorry, I don t understand question 4.

Look this link. I hope it help you.

https://stackoverflow.com/questions/901462/ddd-where-is-it-most-appropriate-to-get-a-list-of-value-objects/901562#901562





相关问题
DDD - Returning entity in response to a service operation

I am new to domain driven development & have a simple question. If a service needs to generate some entity as a response to an operation then how should it be done? One of the ways is to inject ...

Domain Driven Design efforts in dynamic languages? [closed]

Are you aware of any DDD efforts in a dynamic language ? Practical resources on DDD tend to decrease quite dramatically when straying from enterprise-oriented solutions (a google search exluding C#, ....

Accessing domain objects in the view

If I don t want to expose the internal state of my Domain Objects, but I need to display them, I can think of three approaches. Which of these is the most "correct" (if any?). The "DTO/ViewModel ...

DDD screen cast question?

I wathced a screen cast on DDD by Greg Young the other day which spoke about persisting all state transitions of an object, instead of it s state when saved, then to load it "replay" all these ...

How to fluent-map this (using fluent nhibernate)?

I have two tables in my database "Styles" and "BannedStyles". They have a reference via the ItemNo. Now styles can be banned per store. So if style x is banned at store Y then its very possible that ...

热门标签