I use a pattern that I call "ensure" extensively in my repository layer. In short, it does the following when I call an
- It uses the arguments in the method to attempt to populate an entity of a specified type (ultimately from the database),
- If it finds one then it returns it; f it does not, it saves the entity to the database and return it.
So, my Ensure method ensures that there is always a populated entity with specified properties, irrespective of whether one existed before the call was made.
Is there already a more commonly known name for this pattern?