In this application I'm developing, the domain revolves around, say, electrical appliances. There are several specialized versions of this entity. Appliances can be submitted to the application, and this happens from web services using data transfer objects.
While this is working great, I am now looking at importing appliances from several text-based file formats as well. Consider this workflow:
- Directory watcher service sees a new appliance file has been added
- The service uses an application service from my application to submit the appliances described by the file
Now, the application service could have a method with the following name and signature: ApplianceService.Register(string fileContents)
. I'm thinking the directory watcher service will use this service method and pass it the entire contents of the file. The application service will then coordinate the parsing. Parsing the contents of the file and transforming it into complete appliances entities involves several steps. Now, my question is:
Question: Is this correct, or should the parsing logic live within the directory watcher service? Each type of file format is kind of a part of the domain, but then again, it's not. After the files are parsed into entities from either format, the entity will never know that it once was represented using that format. If the parsing logic should live within the watcher service, I would pass the new appliances to the registration service as data transfer objects.
I guess what I'm concerned about is how an appliance should be represented before it enters my application (using the application layer as point of entry). When submitting appliances from web services, I pass a sequence of appliance data transfer objects. This is different from taking a potentially oddly formatted file and parsing that into a data transfer object, since the mapping from the web service request to data transfer object is pretty straight forward, and not that complex.
Any thoughts on this are very much welcome.
According SRP (Single Responsibility Principle), you should keep your consideration.
Directory Watcher service
should do what it does best - watch for new files in a directory and pass them to another service, ieAppliance Service
which converts them into data transfer objects. Now you can use yourweb services
to submit those data transfer objects to the Application.I would make an interface for
Appliance Service
, with at least one method calledConvert()
.Appliance Parsing Service
class can implement the interface. Let's say later you have a different source (SQL) for appliances. You can write another classAppliance SQL Service
that implementsAppliance Service
.