From a DDD perspective is a report generating service a domain service or an infrastructure service?
Let assume we have the following service whose responsibility is to generate Excel reports:
class ExcelReportService{
public String generateReport(String fileFormatFilePath, ResultSet data){
ReportFormat reportFormat = new ReportFormat(fileFormatFilePath);
ExcelDataFormatterService excelDataFormatterService = new ExcelDataFormatterService();
FormattedData formattedData = excelDataFormatterService.format(data);
ExcelFileService excelFileService = new ExcelFileService();
String reportPath= excelFileService.generateReport(reportFormat,formattedData);
return reportPath;
}
}
This is pseudo code for the service I want to design where:
fileFormatFilePath
: path to a configuration file where I'll keep the format of my excel file (headers, column widths, number of columns,..etc)data
: the actual records returned from the database. This data
can't be used directly coz I might need to make further calculations to the data before inserting them to the excel file.ReportFormat
: Value object to hold the report format, has methods
likegetHeaders()
,getColumnWidth()
,...etc.ExcelDataFormatterService
: a service to hold any logic that need to be applied to the data returned from the database before inserting it to the file.FormattedData
: Value object the represents the formatted data to be inserted.ExcelFileService
: a wrapper top the 3rd party library that generates the excel file.
Now how do you determine whether a service is an infrastructure or domain service?
I have the following 3 services here:
ExcelReportService
, ExcelDataFormatterService
and ExcelFileService
?
-
If the report is part of the business process, it could very well be simultaneously a domain service and an infrastructure service. Although, it should be IOC'd out of the domain.Aaron Hawkins– Aaron Hawkins10/30/2014 16:53:03Commented Oct 30, 2014 at 16:53
2 Answers 2
All of it is infrastructure service. Domain in DDD is primarily concerned with data and business rules that operate on this data. It has nothing to do with how the data are presented. So in your example, the only part that would be related to domain is how you get the data
.
-
I see, so following your logic
ExcelDataFormatterService
shouldn't contain any business logic, just presentation logic, right?Songo– Songo05/13/2014 08:52:44Commented May 13, 2014 at 8:52 -
@Songo Yes. Well, it could do a business logic, but only transitively, by calling some kind of domain class, which is not related to excel.Euphoric– Euphoric05/13/2014 10:12:27Commented May 13, 2014 at 10:12
I think you may put it this way: in your specific case if the main purpose of the application / webservice / whatever you are developing is to make reports, then reporting tends to be considered a domain service. Otherwise it is an infrastructure service.
Explore related questions
See similar questions with these tags.