Successors

Initialization:

public void Init(IUnityContainer container)
{
    container.RegisterInstance<IBusinessServiceEventsSuccessor<IAuditableEntity>>(new AuditableSuccessor());
}

Create in interface and set it for entity

public interface IAuditableEntity
{
	DateTime DateCreated { get; set; }

	DateTime? DateLastUpdated { get; set; }
}

public class BlogPost : Int32EntityObject, IAuditableEntity
{		
	public virtual DateTime DateCreated { get; set; }

	public virtual DateTime? DateLastUpdated { get; set; }
	
	...
}

Create a successor

public class AuditableSuccessor : BaseBusinessServiceEventsSuccessor<IAuditableEntity>
{
	public override SuccessorResult OnCreating(IAuditableEntity entity)
	{
		entity.DateCreated = DateTime.Now;

		return SuccessorResult.Default;
	}

	public override SuccessorResult OnUpdating(IAuditableEntity entity)
	{
		entity.DateLastUpdated = DateTime.Now;

		return SuccessorResult.Default;
	}
}

Last edited Apr 1, 2013 at 5:20 AM by olgabutova, version 2

Comments

No comments yet.