kicking off 3rd party processes within common entity actions

Posts   
 
    
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 08-Jul-2011 23:44:31   

Is there a best practice for the following type of use case for an LLBL entity:

Lets say i have an entity Customer, and every time I insert a new Customer in the database i would like to send an email notification somewhere. For whataver reason i am using a 3rd party tiool that generates a nice email and sends it for me.

I need this to happen any time a Customer is inserted into teh database, in any app that uses this generated code. I can't have developers in different apps creating Customers and calling myCustomer.Save() without such an email being generated.

what is the recommended architecture for that scenario?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jul-2011 02:53:27   

Hi nilsey,

I would do this:

  1. Create library project that knows how to send emails. Let call it MailSender.

  2. Create a MailAuditor VS.Net project with a MailAuditor class. This class would be actually a LLBLGen Auditor class. To know more about Auditing please read this. Your auditor should implement the following methods and send emails accordingly:

public override void AuditInsertOfNewEntity(IEntityCore entity)
    {
        // create the mail to be sent
        MailMessage msj = new MailMessage(...);

        // add the mail to the list so we can send them when the transaction is commited
        mailsToBeSent.Add(msj);
    }

public override void AuditUpdateOfExistingEntity(IEntityCore entity)
    {
         // create the mail to be sent
        MailMessage msj = new MailMessage(...);

        // add the mail to the list so we can send them when the transaction is commited
        mailsToBeSent.Add(msj);
    }

Now you have an Auditor listening the Inserts/Updates.

  1. The last step is to assign the Auditor to your entities. Please see the link I posted above to know the ways you can do that (Dependency Injections, explicitly at your code, explicitly in CommonEntityBase...).

That's it. Although auditors are meant to audit actions, this fits to your distribution scenario. Hope helpful wink

David Elizondo | LLBLGen Support Team