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
public class WarehouseProductRepository | |
{ | |
private readonly Dictionary<string, List<IEvent>> _inMemoryStreams = new(); | |
public WarehouseProduct Get(string sku) | |
{ | |
var warehouseProduct = new WarehouseProduct(sku); | |
if (_inMemoryStreams.ContainsKey(sku)) | |
{ | |
foreach (var evnt in _inMemoryStreams[sku]) | |
{ | |
warehouseProduct.ApplyEvent(evnt); | |
} | |
} | |
return warehouseProduct; | |
} | |
public void Save(WarehouseProduct warehouseProduct) | |
{ | |
if (_inMemoryStreams.ContainsKey(warehouseProduct.Sku) == false) | |
{ | |
_inMemoryStreams.Add(warehouseProduct.Sku, new List<IEvent>()); | |
} | |
var newEvents = warehouseProduct.GetUncommittedEvents(); | |
_inMemoryStreams[warehouseProduct.Sku].AddRange(newEvents); | |
warehouseProduct.EventsCommitted(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment