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
    like getHeaders(), 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. 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
    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
    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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.