Skip to content

Develop-Genesis/Cumulo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cumulo

Event sourcing infrastructure library for .Net

Getting Started

 services
    .AddGskiInfrastructure()
    // in memory event store only for testing
    .AddInMemoryEventStore();
    // optional snapshooting is supported
    .AddInMemorySnapshoot();
    // .AddDistributedSnapshoot() -- for distributed cache    

Creating your aggregates

    public class UserDomain : AggregateRoot<Guid>
    {
        const string DType = "User";        
        
        public string FirstName { get; private set; }
        public string LastName { get; private set; }

        public UserDomain() : base(DType, Guid.Empty){}

        public UserDomain(Guid id, IEnumerable<IDomainEventDescriptor> events) : base(Type, id, events) {}

        public UserDomain(string firstName, string lastName) : base(DType, Guid.NewGuid())
        {            
            Dispatch(new CreateUserEvent(){ FirstName = firstName, LastName = lastName });
        }

        public void SetFirstName(string firstName)
        {
            Dispatch(UpdateFirstNameEvent(){ FirstName = firstName });
        }

        public void SetLastName(string lastName)
        {
            Dispatch(UpdateLastNameEvent(){ LastName = lastName });
        }

        // handlers
        void On(CreateUserEvent @event)
        {
            FirstName = @event.FirstName;
            LastName = @event.LastName;
        }

        void On(UpdateFirstNameEvent @event)
        {
            FirstName = @event.FirstName;            
        } 

        void On(UpdateLastNameEvent @event)
        {            
            LastName = @event.LastName;
        }
        
    }

    // Domain Events
    public class CreateUserEvent : ICreateAggregateDomainEvent
    {
        public string FirstName{ get; set; }
        public string LastName{ get; set; }
    }

    public class UpdateFirstNameEvent : IDomainEvent
    {
        public string FirstName{ get; se; }
    }

    public class UpdateLastNameEvent : IDomainEvent
    {
        public string LastName{ get; se; }
    }

Get Repository

    
    public MyCommandContructor(IEventStoreRepository<UserDomain, Guid> repository)
    {
        ...
    }

Add

    
    var user = new UserDomain("Alejandro", "Guardiola");

    repo.Add(user);

Get

    
    var user = await repo.GetAsync(userId);

Update

    
    var user = await repo.GetAsync(userId);
    user.SetFirstName("Jorge");

Remove

    repo.Remove(userId);
    // or
    repo.Remove(user);

Save Changes

    // Inject IEventStore in the constructor
    await eventStore.SaveAsync();

About

Event sourcing infrastructure library for .Net

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages