Giter Site home page Giter Site logo

dario-l / ses Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 1.42 MB

SimpleEventStore is a simple event store library for .NET based on rdbms persistance.

License: MIT License

C# 100.00%
streams cqrs cqrs-es event-sourcing event-store event-stream sql rdbms ms-sql-server

ses's Introduction

**Ses is dead. Long live https://github.com/getmanta/manta ** ...but is still used in production code.

SimpleEventStore

SimpleEventStore SimpleEventStore

SimpleEventStore SimpleEventStore.Abstracts

SimpleEventStore SimpleEventStore.Domain

SimpleEventStore SimpleEventStore.MsSql

SimpleEventStore SimpleEventStore.Subscriptions

SimpleEventStore SimpleEventStore.Subscriptions.MsSql

SimpleEventStore is a simple event store library for .NET based on rdbms persistance.

Main goals
  • Async all the way down (sync methods also available)
  • No external dependencies
  • Pluggable persistance storage
  • Support optimistic (and pesimistic for special cases) concurrency with conflict resolver mechanism
  • Support any kind of serialization through ISerializer interface
  • Support any kind of loggers through ILogger interface
  • Support up-conversion of events/snapshots to the newest version
  • Subscriptions to one or many event stream sources for processmanagers/projections/others (with pluggable stream pollers)
  • Built-in implementation for: MS SQL Server, InMemory
  • Built-in single-writer pattern for MS SQL Server implementation (Linearizer)
Basic example of usage
var options = new TransactionOptions {IsolationLevel = IsolationLevel.ReadCommitted};
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, options, TransactionScopeAsyncFlowOption.Enabled))
{
    var aggregate = new ShoppingCart();
    aggregate.AddItem(SequentalGuid.NewGuid(), name: "Product 1", quantity: 3);


    var stream = new EventStream(id, aggregate.TakeUncommittedEvents());

    // Adding metadata item (key, value)
    stream.Metadata = new Dictionary<string, object>
    {
        { "RequestIP", "0.0.0.0" },
        { "User", "John Doe" }
    };

    var expectedVersion = aggregate.CommittedVersion + stream.Events.Count;
    await _store.SaveChangesAsync(aggregate.Id, expectedVersion, stream);

    scope.Complete();
}

Using repository pattern:

// Usually transaction scope will be hidden somewhere in infrastructural part of code
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, options, TransactionScopeAsyncFlowOption.Enabled))
{
    using (var repo = new SourcedRepo<ShoppingCart>(store))
    {
        // Open stream and restore aggregate from history
        var aggregate = await repo.LoadAsync(id);

        aggregate.AddItem(Guid.NewGuid(), "Product 1", 3);

        await repo.SaveChangesAsync(aggregate);
    }
    scope.Complete();
}
It is working on production already

SimpleEventStore has used in commercial project https://timeharmony.pl already.

ses's People

Contributors

clagoos avatar dario-l avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

ses's Issues

Introduce CommitMetadata and StreamMetadata

CommitMetadata
Each metadata of this type should be correlated with persisted commit (one transaction = one commit).

Example:

{
    "UserId": "9023hdf9238h203h",
    "RequestIp": "127.0.0.1"
}

Currently CommitMetadata is (badly) named StreamMetadata.

StreamMetadata
This type of metadata should be correlated with whole stream of events for all commits.

Example:

{
    "AggregateClrType": "Namespace.TypeName",
    "MaxAge": "14days"
}

New ideas

This issue is for writing some new ideas for next version:

  • stream id as char(60)
  • state of aggregate is not the same as the snapshot (!!!)
  • different metadata (stored separately - no duplication every row)
    • stream metadata
    • commit metadata
  • truncating streams
    • by id
    • before event id
    • max date
    • max count
  • statistics
  • interceptors (eg: caching)
  • performance (!?)
    • single round-trip to the database server (TVP is no-no, too sloooooow)
    • optimized and fine tuned indexes
  • deleted stream should discard all events and publish StreamDeletedEvent instead (to inform subscribers)
    • truncating should do the same, that is publish StreamTruncatedEvent
  • should have an option to make stream read-only
  • no sprocs (tests shows that is not needed)
  • projections
    • projector should not update checkpoint in datastore when event is not handled by projection
    • subscribing should be more explicit
    • replaying projections needs more love (eg: waiting for catching up)
  • tracking (metadata or dedicated columns in MsSql implementation ?)
    • eventId
    • correlationId
    • causationId

AggregateSnapshot should return State as IMemento

Current implementation of AggregateSnapshot do not allow to replace snapshot instance. Aggregate should have possibility to return any type of IMemento implementation.

public override IAggregateSnapshot GetSnapshot()
{
    return new AggregateSnapshot(CurrentVersion, new MyNewSnapshot());
}

Things to do:

  • AggregateSnapshot class should be public
  • AggregateSnapshot should not be generic
  • AggregateSnapshot should return State as IMemento

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.