Domain Driven Design - Where Data Analysis Is Performed

In this application that I am developing, the domain revolves around, say, electrical appliances. There are several specialized versions of this object. Applications can be submitted to the application, and this comes from web services using data transfer objects.

While this works fine, now I'm looking to import devices from several text file formats. Consider this workflow:

  • The directory watcher service sees that a new device file has been added.
  • The service uses the application service from my application to send the devices described in the file

Now the application service can have a method with the following name and signature: ApplianceService.Register(string fileContents) . I think that the directory browsing service will use this service method and pass all the contents of the file to it. Then the application service will coordinate the parsing. Parsing the contents of a file and converting it into objects of complete hardware involves several steps. Now, my question is:

Question: Is this correct, or should the parsing logic live in the directory observer service? Each type of file format is part of the domain, but again, it is not. After files are analyzed in an entity from any format, the entity will never know that it was once represented using this format. If the parsing logic should live in the observer service, I will transfer the new devices to the registration service as data transfer objects.

I suppose I'm worried about how the device should be presented before it enters my application (using the application layer as an entry point). When sending devices from web services, I pass a sequence of device data transfer objects. This is different from the fact that you make a potentially strangely formatted file and parse it into a data transfer object, since the mapping from a web service request to a data transfer object is pretty straightforward, and not so complicated.

Any thoughts on this are very welcome.

+7
source share
2 answers

According to the SRP (principle of single responsibility), you must keep your opinion. Directory Watcher service should do what it does best - keep track of new files in the directory and transfer them to another service, i.e. Appliance Service , which converts them into data transfer objects. Now you can use web services to send these data transfer objects to the application.

I would make an interface for the Appliance Service with at least one method called Convert() . Appliance Parsing Service class can implement an interface. Say later, you have another source (SQL) for fixtures. You can write another Appliance SQL Service class that implements the Appliance Service .

+1
source

I would say that the ApplicationService is the right place for the parsing logic, considering that it will not be a really bad way to put it in the DirectoryWatcher service.

My reasoning for this statement is based on the principle of the Single Responsibility Principle: DirectoryWatcher, in particular, should not be responsible for managing all input file formats. He should just grab what he receives and transfer it to the right place (already a very responsible responsibility).

Where did my head turn a little (which maybe just like you?) Was that this is actually not the responsibility of the ApplicationService that coordinates your various domain entities. However, I believe that ApplicationService is the right place to use some kind of Builder pattern, abstracting the details of each analysis method of each file, and also creating a clear place in the Domain where this parsing is coordinated.

As for each file format that is part of the domain, and without it. I would say that they exist - you can imagine that they are all expressed as part of the ubiquitous language, and various experts in the field talk about the quirks of the file format x or file format y and expressed data. This type of analysis and comparison is, first of all, the logic of a first-class domain.

Another nice side of your original design is that I think it will make it easier to add new formats and formats and modify existing ones. You have separated the file source from a specific format and created a nice interface point (ApplicationService) where your new file providers access the main applications.

+1
source

All Articles