On Wed, Oct 29, 2008 at 10:26 AM, Billy Stack <[EMAIL PROTECTED]> wrote:

> All,
>
> Apologies on repeating the same request twice. I thought the first request
> didnt work so Im sincerely sorry in posting twice on the same topic.
>
> Fabio, to answer the questions you asked:
>


> 1.    do you have invalid instance in the DB ?
>


> We shouldnt have invalid instances in the database but when we get our
> entity out of the database, we still want it constructed by the constructor
> with guard clauses so it absolutely guarantees that the entity is in a valid
> state (following DDD guidelines for value types which should be immutable)
>


> 2.     do you really want that your class throw an exception in a fresh
> load from DB?
>
   Yes we do. If any value type entity is deemed invalid we want to
automatically throw an exception.

Is there any way to call the constructor that has the guard clauses?

Many thanks,
bstack


>
>
>
> On Sat, Oct 25, 2008 at 11:14 AM, Fabio Maulo <[EMAIL PROTECTED]>wrote:
>
>> Repeated request. Our friend bstack is something impatient.
>>
>> 2008/10/22 bstack <[EMAIL PROTECTED]>
>>
>>
>>> All,
>>>
>>> We are using immutable types in our domain, that we want to map
>>> directly to to database. The type takes the following format:
>>>
>>> public class X
>>> {
>>>      private readonly int m_Prop1;
>>>      private readonly int m_Prop2;
>>>
>>>      private X() { }
>>>
>>>      public X(int p1, int p2)
>>>      {
>>>          //Perform validation guard check against arguments
>>>
>>>          this.m_Prop1 = p1;
>>>          this.m_Prop2 = p2;
>>>      }
>>>
>>>      public int Prop1 { get { return this.m_Prop1; } }
>>>      public int Prop2 { get { return this.m_Prop2; } }
>>> }
>>>
>>> The problem we have is that the private constructor is what NHibernate
>>> instantiates (not the public constructor where guard checks are
>>> performed), hence we can end up "getting" an instance of X from the
>>> database that is invalid.
>>>
>>> Is there any way to get NHibernate to call the constructor that
>>> performs the guard checks?
>>>
>>>
>>>
>>
>>
>> --
>> Fabio Maulo
>>
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to