We can always start sprinkling code like this around but how do we
rationalize that its actually happening?

One question ... here you seem to have order and customer as two
aggregate roots, I am more worried about what happens when its
something within our aggregate root. Again we could use the locking
but is that something that we want to have to do ourselves?

consider

Customer
    Contact
          Address

for the sake of discussion let's imagine that these are all entities ..

Customer c = CustomerRepo.Fetch(id);
c.Contact.Address.Street = "testing";
UnitOfWork.Commit();


Basically I want nhibernate to trigger my AR for validation of the
whole AR (and versioning of the whole AR) when an sub-piece is
changed. We could use locking etc as you mention but that strikes me
as bug prone, what if someone forgets to sprinkle that 1 line of code
somewhere?

Greg

On Mon, Apr 27, 2009 at 12:31 PM, Peter Morris <[email protected]> wrote:
>
>>>
> with AOP the problem is finding the root (it might be 5 levels deep).
> I was looking at Peter's suggestion but don't like what it requires. I
> am currently looking at a way to do this only in proxies but the trick
> is in finding out what aggregate root we are under while not having
> the id carried by the domain objects ... One thing I see is having the
> IHaveParentId be implemented by the proxy ... then have an
> IAggregateRoot for the actual parent ... so you can just keep walking
> up the path but none fo the objects carry the ids themselves. As I go
> through this though I keep hearing "too much magic" being whispered in
> my ear.
> <<
>
> There is something I am not understanding about your problem, the problem I
> see is entirely different.
>
> Here is how I see your scenario where a new order is raised (the agg-root
> being order) and checking that the customer's limit isn't exceeded.
>
>
> using (var session = SessionFactory.OpenSession())
> using (var transaction = session.BeginTransaction())
> {
>    var customer = CustomerRepository.Load(customerID, LockMode.Write);
> //Fetch a proxy only***
>    var newOrder = new Order(customer, ...................);
>    //continue setting up the order
>
>    ValidateTheOrder;
>    customer.AcceptOrder(newOrder);
>    session.Save(newOrder);
>    transaction.Commit();
> }
>
> The Order is validated, and the Customer is certain to not have been updated
> by another user.
>
> The part I have marked *** is the bit I see as the problem, and that is "How
> do I ensure nobody updates the customer?".  Typically I would make sure the
> Customer is updated too but it seems in NH you can't force a version update
> on an object that is not dirty, so I am guessing that the LockMode is the
> solution, however I believe that is DB dependent and not all databases will
> support it.  If it is in fact possible to update a non-dirty entity (to
> ensure agg-parts are valid) then you would add Session.Update(customer) too,
> but I suspect that is not possible.
>
> Is there something about your problem that I am missing?
>
>
>
> Pete
>
>
> >
>



-- 
It is the mark of an educated mind to be able to entertain a thought
without accepting it.

--~--~---------~--~----~------------~-------~--~----~
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