Andrea Bardelli
Andrea Bardelli

Reputation: 190

persisting presentation-infrastructure-specific data in a DDD application

I have a DDD application, with its Domain, Application and Presentation layers.

My presentation layer needs to persist some configuration that have nothing to do with the application but rather with the behaviour of certain UI elements.

Since they are tied to a specific presentation infrastructure, i don't like the idea of introducing dedicated services in the application layer..
On the other hand creating a dedicated persistency infrastructure just for the presentation-component doesn't sound right either and (more importantly) it's a lot of (redundant) work: all the data-access and repository seedwork already exists in the application layer!

This must be a common necessity, for example a fronted may want to save user-specific preferences in an application otherwise not concerned with users.

Has anyone any good pointers on literature/patterns/articles or the like that may answer this?

-- the concrete case --
The application is a .NET app using EF, a repository pattern and WPF as a frontend.
The application autonomously runs scans and coordinates various machines.
The frontend allows to inspect the results.
The application allows to bind "custom properties" to completed scans; (simple key-value string pairs)

The UI controls for this "custom properties" sometimes are to be populated with default values, sometimes not. The UI needs to know for each CustomProperty wether to apply this behaviour or not. Basically to store a configuration for each kind of property.
This is not a "user preference" but it's not something that all frontends will need either.

I already have a "configuration" Entity for the infrastucture-agnostic parts

public class CustomPropertySpec : Entity
{
   public CustomPropertySpec(string name, string defaultValue, bool hasPresets, bool isValidating, string validationRegex)
   {
      this.Name = name ?? throw new ArgumentNullException(nameof(name));
      this.DefaultValue = defaultValue;
      this.HasPresets = hasPresets;
      this.IsValidating = isValidating;
      this.ValidationRegex = validationRegex ?? throw new ArgumentNullException(nameof(validationRegex));
      this.Presets = new HashSet<CustomPropertySpecPreset>();
      this.Localizations = new HashSet<CustomPropertySpecLocalization>();
   }

   /// <summary>
   /// Initializes a new instance of the <see cref="CustomPropertySpec"/> class.
   /// </summary>
   protected CustomPropertySpec()
   {
      this.Presets = new HashSet<CustomPropertySpecPreset>();
      this.Localizations = new HashSet<CustomPropertySpecLocalization>();
   }

   public string Name { get; set; }

   public string DefaultValue { get; set; }

   public ICollection<CustomPropertySpecPreset> Presets { get; set; }

   public ICollection<CustomPropertySpecLocalization> Localizations { get; set; }

   public bool HasPresets { get; set; }

   public bool IsValidating { get; set; }

   public string ValidationRegex { get; set; }

   public bool Validate(string value)
   {
      if (!this.IsValidating)
      {
         return true;
      }
      else
      {
         Regex regex = new Regex(this.ValidationRegex, RegexOptions.IgnoreCase);
         return regex.IsMatch(value);
      }
   }

}

and i could just add another couple of booleans here, for whatever config the frontend may need. But this couples the domain to a specific infrastructure.

Upvotes: 1

Views: 23

Answers (0)

Related Questions