Event sourcing infrastructure library for .Net
services.AddGskiInfrastructure()// in memory event store only for testing.AddInMemoryEventStore();// optional snapshooting is supported.AddInMemorySnapshoot();// .AddDistributedSnapshoot() -- for distributed cache publicclassUserDomain:AggregateRoot<Guid>{conststringDType="User";publicstringFirstName{get;privateset;}publicstringLastName{get;privateset;}publicUserDomain():base(DType,Guid.Empty){}publicUserDomain(Guidid,IEnumerable<IDomainEventDescriptor>events):base(Type,id,events){}publicUserDomain(stringfirstName,stringlastName):base(DType,Guid.NewGuid()){Dispatch(newCreateUserEvent(){FirstName=firstName,LastName=lastName});}publicvoidSetFirstName(stringfirstName){Dispatch(UpdateFirstNameEvent(){FirstName=firstName});}publicvoidSetLastName(stringlastName){Dispatch(UpdateLastNameEvent(){LastName=lastName});}// handlersvoidOn(CreateUserEvent@event){FirstName=@event.FirstName;LastName=@event.LastName;}voidOn(UpdateFirstNameEvent@event){FirstName=@event.FirstName;}voidOn(UpdateLastNameEvent@event){LastName=@event.LastName;}}// Domain EventspublicclassCreateUserEvent:ICreateAggregateDomainEvent{publicstringFirstName{get;set;}publicstringLastName{get;set;}}publicclassUpdateFirstNameEvent:IDomainEvent{publicstringFirstName{get;se;}}publicclassUpdateLastNameEvent:IDomainEvent{publicstringLastName{get;se;}}publicMyCommandContructor(IEventStoreRepository<UserDomain,Guid> repository){
...}varuser=newUserDomain("Alejandro","Guardiola");repo.Add(user);varuser=awaitrepo.GetAsync(userId);varuser=awaitrepo.GetAsync(userId);user.SetFirstName("Jorge");repo.Remove(userId);// orrepo.Remove(user);// Inject IEventStore in the constructorawaiteventStore.SaveAsync();