How to temporarily circumvent domain object's creation contracts when restoring application from backup?

79 views Asked by At

Our application's domain model objects have constructors with nontrivial contracts. For example an Entry object requires a Catalog object in order to be created. The problem is, these contracts have to be violated temporarily when I'm doing bulk restore of objects from XML file as the dependent objects might not be available until the backup file is fully processed.

Is there any established pattern or solution to this problem?

1

There are 1 answers

0
Eben Roux On BEST ANSWER

There are going to be a number of ways to do this.

Is there any established pattern or solution to this problem?

What springs to mind is the momento pattern.

It is probably quite apparent that using your current constructor will not get the job done :) --- so you will need to use another method call.

You may use another constructor if you have arguments that can get to it.

In a C# world (I'm sure similar, or better, constructs exist in other languages) you could go as far as to make the method / constructor internal and use the InternalsVisibleToAttribute to give your bulk loader access.