CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Why is Initialize not called from OnDeserializedHandler?

rated by 0 users
This post has 3 Replies | 2 Followers

Top 500 Contributor
Posts 22
JoshL Posted: Sun, Apr 12 2009 12:42 AM
According to the code comment, Csla.Core.Initialize "allows subclass to initialize events before any other activity occurs". It is called from the constructor of BusinessBase, before any initialization of business rules or authorization rules. However, it is not called on deserialize of the object. Why is this?
Top 10 Contributor
Posts 9,270
You should override OnDeserialized() to do any event rehooking and so forth.

Rocky

Top 500 Contributor
Posts 22
JoshL replied on Mon, Apr 13 2009 10:45 AM
I understand that, but don't understand what the point of Initialize is in that case.

Implementing OnDeserliazed for the same functionality as Initialize is inconsistent: Initialize runs _before_ CSLA's initialization on constructor, but OnDeserialized runs _after_ CSLA's initialization. There is no way to run initialization logic _before_ OnDeserialized.

If I need to override OnDeserialized anyways, why not simply implement the custom event hooking in the constructor of the descendant class, in order to keep the timing consistent?
Top 10 Contributor
Posts 9,270
Semantically they aren't necessarily the same.

Initialize() exists so you can initialize elements of your object when it is
first created.

OnDeserialized() exists so you can reset elements of your object after it
has been deserialized.

Some elements of your object may need initialization only. Others may need
to be reset on deserialization only. Others may need both.

So I don't necessarily disagree with the concept of an "OnDeserializing()"
method - though it would still technically run after deserialization is
complete (because we don't control that - deserialization is purely a .NET
thing). But this is still not the same semantic operation as initializing a
new object instance.

What is your scenario where you need to reset elements of your object after
deserialization, but before CSLA restores values like the Parent property,
etc?

Rocky

Rocky

Page 1 of 1 (4 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems