Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.57 KB

EfCoreSetup.md

File metadata and controls

48 lines (36 loc) · 1.57 KB

Setup EF Core event store

  1. Install NuGet package JKang.EventSourcing.Persistence.EfCore

    PM> Install-Package JKang.EventSourcing.Persistence.EfCore
  2. According to your requirement, select database engine and install corresponding NuGet package. For example Microsoft.EntityFrameworkCore.InMemory

    PM> Install-Package Microsoft.EntityFrameworkCore.InMemory
  3. 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;
        }
  4. Register event sourcing services in ConfigureServices()

    services
        .AddDbContext<SampleDbContext>(x => x.UseInMemoryDatabase("local"));
    
    services
        .AddEventSourcing(builder =>
        {
            builder
                .UseEfCoreEventStore<SampleDbContext, GiftCard, Guid>();
        });