Search code examples
configurationdomain-driven-design

DDD: User defined infrastructure configurations


I am working on an application and am moving to DDD (more specifically Onion Architecture) with the following layers: Presentation (separated into GUI and CLI), Infrastructure, Application, Domain

The domain entities are presented to the user in the CLI or GUI and the user has the possibility to set a range of different configurations which are saved in a JSON file. Some of the configurations are for persistence configurations like whether to use local file storage using JSON files or a database. For local storage the user can set the default save location on disk.

When presenting the entities to the user I also need to show the save location of the JSON file for a specific entity if it is saved to disk.

Since persistence topics should not be included in the domain I wonder how to handle these configurations and pass information about the save location from the Infrastructure Layer to the Presentation Layers. My understanding is that the Application Layer should be very thin and only consist of services and should also not have any details about persistence.

Is it possible to create a config model located in the Application Layer that both the Infrastructure and Presentation layers can use?


Solution

  • Of course it's possible to do so (and if you happen to be planning to take advantage of a framework, you'll want to choose a framework which doesn't enforce such a restriction).

    DDD generally advised not doing this because in most cases concerns like this are extraneous to the problem you're trying to solve. But in this case it seems that persistence is something that you're modeling in the domain.

    It may in fact be most useful to have a persistence bounded context with its own onion and have the other bounded contexts use that (e.g. in their infrastructure layers).