Keith,

Thanks for the response. Perhaps it isn't all too bad to send the mail from the 
Model. It didn't feel right at first because I felt that the Controller should 
be responsible for the direct communication with the user. I filed 'mailing the 
user' under the same responsibilities.

I like your idea of the MailService. I'm going to implement something similar 
now. Thanks!



> Date: Sat, 28 Feb 2009 16:55:35 +0000
> Subject: Re: [fw-general] Controller / Model routines
> From: [email protected]
> To: [email protected]
> CC: [email protected]
> 
> I dont see a problem with having your Model send the email, what I
> would do though is put the mail code into a service, this way you keep
> mail logic out of your Model. This way for testing you can replace
> your mail service easily :)
> 
> Model->signup()
> {
>   ModelDbTable->startTransaction()
>   try
>   {
>     ModelDbTable->insert()
>     MailService->send();
>     ModelDbTable->commit()
>     return true
>   }
>   catch( Exception )
>   {
>     ModelDbTable->rollBack()
>     return false
>   }
> }
> 
> 2009/2/28  <[email protected]>:
> > Hey all,
> >
> > I'm trying to determine how I can have my Model rollback a transaction it
> > made on a DB table when the calling Controller fails to send a confirmation
> > mail afterwards. What is good practice? Am I approaching this in the wrong
> > way perhaps? Should I send the Mail from within the Model? That just doesn't
> > feel right. I'ld love to read your suggestions. Thank you in advance.
> >
> > In short this is what happens now in pseudo code (please read the comments
> > inside the first catch, where I try to convey my point):
> >
> > == Controller ==
> > Controller->signup()
> > {
> >   if( true == Model->signup() )
> >   {
> >     try
> >     {
> >       Mail->send()
> >     }
> >     catch( Exception )
> >     {
> >      // seems stupid to have the Model roll back the transaction from here,
> > no?
> >     }
> >   }
> >   else
> >   {
> >     // do something when Model->signup() failed
> >   }
> > }
> >
> > == Model ==
> > Model->signup()
> > {
> >   ModelDbTable->startTransaction()
> >   try
> >   {
> >     ModelDbTable->insert()
> >     ModelDbTable->commit()
> >     return true
> >   }
> >   catch( Exception )
> >   {
> >     ModelDbTable->rollBack()
> >     return false
> >   }
> > }
> >
> >
> > Cheers
> >
> > ________________________________
> > Twee keer zo leuk. Deel foto's terwijl je chat met de nieuwe Messenger
> 
> 
> 
> -- 
> ----------------------------------------------------------------------
> [MuTe]
> ----------------------------------------------------------------------


_________________________________________________________________
De leukste online filmpjes vind je op MSN Video!
http://video.msn.com/video.aspx?mkt=nl-nl

Reply via email to