Created
January 13, 2012 17:21
-
-
Save seburgi/1607610 to your computer and use it in GitHub Desktop.
A wrapper for IAtomicWriter (see Lokad.CQRS.Sample) that calls a provided action after successful updates/deletes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class PublishingAtomicWriter<TKey, TEntity> : IAtomicWriter<TKey, TEntity> where TEntity : class | |
{ | |
private readonly IClientNotificationService _clients; | |
private readonly IAtomicWriter<TKey, TEntity> _writer; | |
private readonly Action<TKey, TEntity> _publishAction; | |
public PublishingAtomicWriter(IAtomicWriter<TKey, TEntity> writer, Action<TKey, TEntity> publishAction) | |
{ | |
if (publishAction == null) throw new ArgumentNullException("publishAction"); | |
_writer = writer; | |
_publishAction = publishAction; | |
} | |
public TEntity AddOrUpdate(TKey key, Func<TEntity> addFactory, Func<TEntity, TEntity> update, AddOrUpdateHint hint = AddOrUpdateHint.ProbablyExists) | |
{ | |
var entity = _writer.AddOrUpdate(key, addFactory, update, hint); | |
if(entity != null) | |
_publishAction(key, entity); | |
return entity; | |
} | |
public bool TryDelete(TKey key) | |
{ | |
var success = _writer.TryDelete(key); | |
if(success) | |
_publishAction(key, null); | |
return success; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment