Last active
June 21, 2017 19:21
-
-
Save Odonno/853904e488b3f87fe340c774380d31ff to your computer and use it in GitHub Desktop.
App Event Store (in C# using Entity Framework)
This file contains hidden or 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 AppEvent | |
{ | |
public long Id { get; set; } | |
public string Name { get; set; } | |
public DateTime CreationDate { get; set; } | |
public string Data { get; set; } | |
} |
This file contains hidden or 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 interface IAppEventStore | |
{ | |
void Push<T>(string eventName, T data); | |
} | |
public class AppEventStore : IAppEventStore | |
{ | |
private DbContext _dbContext; | |
public AppEventStore(DbContext dbContext) | |
{ | |
_dbContext = dbContext; | |
} | |
public void Push<T>(string eventName, T data) | |
{ | |
var appEvent = new AppEvent | |
{ | |
Name = eventName, | |
CreationDate = DateTime.Now, | |
Data = JsonConvert.SerializeObject(data) | |
}; | |
_dbContext.AppEvents.Add(appEvent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment