Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reinject dependencies of a freshly deserialized object

If a program has literally just deserialized an object (doesn't really matter how, but just say BinaryFormatter was used).

What is a good design to use for re-injecting the dependencies of this object?

Is there a common pattern for this?

I suppose I would need to wrap the Deserialize() method up to act as a factory inside the container.

Thanks!

like image 562
nbevans Avatar asked Feb 04 '23 04:02

nbevans


1 Answers

You shouldn't serialize objects with dependencies that can't themselves be serialized.

Instead, split it into two classes: extract the serializable parts into a separate class.

After deserializing, you can associate the resulting object with an instance of the original class (the one with dependencies).

like image 139
Jeff Sternal Avatar answered Feb 07 '23 11:02

Jeff Sternal