Hi,
I have an entity structure as follows:
IManager: IDeletable
{
IEnumerable<IFund> Funds {get;}
IFailureNotification Delete();
}
IFund : IDeletable
{
IEnumerable<IFundClass> FundClasses
IFailureNotification Delete();
}
IFundClass: IDeletable, IInvestable
{
IFailureNotification Delete();
}
And I have a service which takes an IDeletable
and calls Delete on it. Depending on the return value it then either commits the transaction or rolls it back. I'm using NHibernate to persist the classes so can't put RI in the DB and catch the exception (which I wouldn't like anyway).
This is a classic case for polymorphism and the Manager
loops through its Funds
and deletes them before deleting itself, the Fund
in turn delete the FundClass
es before deleting themselves, so the service can just take any entity implementing IDeletable
and know that the deletion will perform the appropriate actions at all levels.
Here's the problem: The fund classes need to find if they're being used in a completely separate context using the IInvestable
interface which they don't know anything about. This requires a service - the IInvestmentCalculationService
.
Obviously I don't want to inject the InvestmentCalculationService
into the fund class entity constructor and I don't want to inject it into the delete method as this is on Funds and Managers as well as many other classes so doesn't make any sense - also means that as soon as we have more requirements we have to change the delete methods on everything.
I'm a bit tempted by the Domain Events model here: http://www.udidahan.com/2009/06/14/domain-events-salvation/ but I'm not confident that it's right as I'm trying to get data back from the triggered event handler - which would work but smells a little bit wrong, and all the examples only show fire and forget situations.
Does anyone have any suggestions?