-
Install NuGet package JKang.EventSourcing.Persistence.EfCore
PM> Install-Package JKang.EventSourcing.Persistence.EfCore
-
According to your requirement, select database engine and install corresponding NuGet package. For example Microsoft.EntityFrameworkCore.InMemory
PM> Install-Package Microsoft.EntityFrameworkCore.InMemory
-
Create the DbContext containing the table for storing events
public class SampleDbContext : DbContext, IEventDbContext<GiftCard, Guid> { public SampleDbContext(DbContextOptions<SampleDbContext> options) : base(options) { } public DbSet<EventEntity<Guid>> GiftCardEvents { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new EventEntityConfiguration<Guid>()); } DbSet<EventEntity<Guid>> IEventDbContext<GiftCard, Guid>.GetEventDbSet() => GiftCardEvents; }
-
Register event sourcing services in ConfigureServices()
services .AddDbContext<SampleDbContext>(x => x.UseInMemoryDatabase("local")); services .AddEventSourcing(builder => { builder .UseEfCoreEventStore<SampleDbContext, GiftCard, Guid>(); });