Skip to content

Instantly share code, notes, and snippets.

@Odonno
Last active June 21, 2017 19:21
Show Gist options
  • Save Odonno/853904e488b3f87fe340c774380d31ff to your computer and use it in GitHub Desktop.
Save Odonno/853904e488b3f87fe340c774380d31ff to your computer and use it in GitHub Desktop.
App Event Store (in C# using Entity Framework)
public class AppEvent
{
public long Id { get; set; }
public string Name { get; set; }
public DateTime CreationDate { get; set; }
public string Data { get; set; }
}
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