Hey,
I've been reading through a number of DDD discussions and realized that
we really need to have a good way to do Validation, and which should be
tied to the UoW.complete() operation.
For example, if a dialog does some changes on an Entity, then it should
get some callback so that when UoW.complete() is invoked it gets a
chance to do Validation on its internal state, and if it is not ok then
an exception is raised, with messages that can be shown to the user to
be either fixed or the UoW should be discarded by clicking Cancel in the
dialog.
In order to get this going as easily and flexibly as possible I
therefore added the following method to UnitOfWork:
void registerUnitOfWorkSynchronization(UnitOfWorkSynchronization
synchronization);
where:
public interface UnitOfWorkSynchronization
{
void beforeCompletion()
throws UnitOfWorkCompletionException;
void afterCompletion(UnitOfWorkStatus status);
enum UnitOfWorkStatus
{
COMPLETED, DISCARDED
}
}
---
The synchronization callbacks would be invoked before completion, and
allows them to raise UnitOfWorkCompletionExceptions, and after
completion or discard they can do optional cleanup or similar.
To get Validation working with this I then changed the current
ValidatableMixin in the framework extension to register a UoWSynch when
it is instantiated that calls validate() in beforeCompletion().
In other words, if you are accessing an Entity in a UoW, and the Entity
implements Validatable, it will automatically register itself with the
UoW to allow the validation checks to happen upon completion().
Then, in order to access Entity-specific validation rules you simply add
Concerns to the validate() method, either by extending
ConcernOf<Validatable> or by using the AbstractValidatableConcern base
class which provides extra features for easy rule checking and i18n of
error messages.
I think this will provide a good-enough mechanism for Validation checks,
and if there are any rules that needs to be checked and which cannot be
done through the Validatable interface, then simply add custom
synchronization callbacks in the UoW manually.
Does this sound ok?
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev