GithubHelp home page GithubHelp logo

Support for non-Guid Identity about cqrslite HOT 4 CLOSED

gautema avatar gautema commented on July 27, 2024 1
Support for non-Guid Identity

from cqrslite.

Comments (4)

gautema avatar gautema commented on July 27, 2024

from cqrslite.

petersondrew avatar petersondrew commented on July 27, 2024

I just finally got around to finishing up a proof-of-concept implementing an IIdentity. I included an out-of-the-box GuidIdentity implementation. Those of us who need something more advanced can easily do so.

from cqrslite.

andymacdonaldac avatar andymacdonaldac commented on July 27, 2024

We faced a similar issue, internally we name our streams typename-aggregateid so for an Availability aggregate the stream would be named something like availability-d0057d1d-b431-42f3-b8ff-bc536a9ea286.

The first thing we did was to add an ITypedEventStore interface which replicated the IEventStore interface but adds an aggregateTypeName parameter to the start of the Get and Save methods:

public interface ITypedEventStore
{
    Task<IEnumerable<IEvent>> Get(string aggretateTypeName, Guid aggregateId, int fromVersion, CancellationToken cancellationToken = default(CancellationToken));
    Task Save(string aggretateTypeName, IEnumerable<IEvent> events, CancellationToken cancellationToken = default(CancellationToken));
}

We created a new TypedRepository which implements IRepository and takes an ITypedEventStore in it's constructor.

private readonly ITypedEventStore _eventStore;

public TypedRepository(ITypedEventStore eventStore)
{
    _eventStore = eventStore ?? throw new ArgumentNullException(nameof(eventStore));
}

Then using reflection we pulled out the type name of the aggregate inside the Save and LoadAggregate methods e.g.

public async Task Save<T>(T aggregate, int? expectedVersion = null, CancellationToken cancellationToken = default(CancellationToken)) where T : AggregateRoot
{
 string typeName = aggregate.GetType().Name.ToLower();
}

and

private async Task<T> LoadAggregate<T>(Guid id, CancellationToken cancellationToken = default(CancellationToken)) where T : AggregateRoot
{
string typeName = typeof(T).Name.ToLower();
}

That type name ultimately gets passed to the ITypedEventStore implementation which is this case pushes to GetEventStore.

It's still very much a work in progress and some of the type names can probably be changed to something better but it works for us at the moment. I've attached the files we used and if anyone think's it worthwhile I'm happy to take a fork, make the changes and open a proper PR.

Code.zip

Andy

from cqrslite.

bdongus avatar bdongus commented on July 27, 2024

In the beginnig I too had problems with the id being a Guid. After some meditation I wouldn't introduce a non-Guid id.
Those ids are IMHO a dependency to some sort of storage and legacy to data driven thinking. Autogenerated integer ids. As soon as you have a distributed storage scenario you are screwed using them.
I use the autogenerated integer id as clustering index and the the Guid as unique index.
That way you prevent the disk acitivity caused by the Guid as clustering index.

from cqrslite.

Related Issues (20)

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.