The .NET event pattern cannot be used here, it follows the pattern fire and
forget, and it's not what I'm searching as I want to be able to interact
with the DataMapper workflow engine, you must see them as extension point
where you can change the items that the engine is working on.
It can be used for all sorts of cross-cutting concerns

Example, replace the resultMap object instance by a proxy one, add/change
arguments used by the constructor in the resultMap...

private class MyPreCreateEventListener : PreCreateEventListener
{
    /// <summary>
    /// Calls before creating an instance of the <see cref="IResultMap"/>
object.
    /// </summary>
    /// <param name="evnt">The event.</param>
    /// <returns>
    /// Returns is used as constructor arguments for the instance being
created
    /// </returns>
    public override object OnEvent(PreCreateEvent evnt)
    {
    evnt.Parameters[evnt.Parameters.Length-1] = "new lastName";

    return evnt.Parameters;
    }
}

Example

private class MyPreInsertEventListener :PreInsertEventListener
{

    /// <summary>
    /// Calls on the specified event.
    /// </summary>
    /// <param name="evnt">The event.</param>
    /// <returns>Returns is used as the parameter object</returns>
    public override object OnEvent(PreInsertEvent evnt)
    {
    IDomain domain = evnt.ParameterObject as IDomain;
        if (domain != null)
    {
            ProcessBeforeInsert(domain);
    }

    return account;
    }

    private void ProcessBeforeInsert(IDomain domain)
    {
        User user = (User) Thread.CurrentPrincipal;
        domain.CreatedBy = user.UserName;
        domain.ModifiedBy = user.UserName;
        domain.CreatedDate = DateTime.Now;
        domain.ModifiedDate = DateTime.Now;
    }
 }

-- 
Cheers,
Gilles

Reply via email to