Re-register a singleton during deserialization

Dec 12, 2013 at 6:55 PM
I have searched and do not see any discussion which quite hits this point. There are some similar but not quite.

During a deserilization of an object graph some of the objects in the graph were (before serialization) created via Unity and registered as a singleton via RegisterInstance,

The deserialization will recreate the objects just fine. But the singleton instances will not be registered with the current instance of the container.

Case 1: The instance is not registered and needs to be.
Case 2: The instance is not registered, but another is and there needs to be a swap.

Is there any facility/pattern/approach to managing this case?
Dec 13, 2013 at 4:11 PM
Prevent mixing data objects (that you send over the wire) with services (that you register in your container). Your data object should not depend on any services. The problems you have are caused by letting data objects depend on services.
Editor
Dec 14, 2013 at 5:39 AM
You will have to manually re-register the classes. You shouldn't have to do any special logic -- just call RegisterInstance and if it's a new instance it will be registered and if there is already a registration it will be overwritten.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
[Support How-to](http://entlib.codeplex.com/wikipage?title=Support%20How-t