Say I have an entity which represents a template that a user can use to create documents. The user can type a given pattern to insert placeholders i.e. {{placeholder name}} into the template so that this can be used as a template for other documents.
So for example if the user typed "This is a {{placeholder1}} letter and can be used for {{placeholder2}} or {{placeholder3}}." then this would create a Template entity with three placeholders given the pseudo code below.
class Template {
int Id { get; set; }
string Text { get; set; }
IEnumerable<Placeholder> placeholders { get; set;}
}
class Placeholder {
int Id { get; }
string Name { get; }
}
When a user creates a document from the template they don't neccessarily have to use all placeholders so therefore the template creator can update the template and delete a placeholder if it hasn't been used in any documents.
I am trying to understand using DDD how or where I would implement the parsing of the text of the template and also where would I check to see if a placeholder has been used in a document derived from the template.
My thoughts are that for the given example above the template editor user could update the text to "This is a letter and can be used for {{placeholder2}} or {{placeholder3}}." I would need to parse the text and pull out the placeholders and then I would need to go to the database to see if the missing place holder i.e. {{placehodler1}} had been used in any derived documents.
The thing I can't get my head round though is I am assuming that I would need a service to check the database and validate the new text. To do this it would first need to parse the text entered and extract the placeholders and then do the database check. If the text was valid I would then set the text property on Template entity which would have to be parsed again in order to pull out the placeholders, therefore I am repeating the parsing functionality in my service and entity.
Has anybody any idea on a design which would work in this scenario or how this would be best achieved using DDD? Do I inject a service into the Template entity which would do this or do I pass the entity to a service etc?
I'm just after a bit of top level design advice or a nod in the right direction.
Regards, Gary
Aucun commentaire:
Enregistrer un commentaire