Comments (4)
from cqrslite.
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.
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.
Andy
from cqrslite.
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)
- Concurrency errors HOT 7
- Error EventIdIncorrectException in the new version HOT 2
- Snapshot aggregte returns an aggregate with default values. HOT 8
- Another article about CQRSlite HOT 1
- Where are the query and event handlers being registered? HOT 1
- Not sure if this is a bug or intentional... HOT 3
- Question about events and new commands HOT 4
- How to "rollback" to a specific version? HOT 2
- Are async handlers waited? HOT 1
- Untyped Save<T> when calling from Session HOT 2
- Project maintained?
- How to handle the version property in react or angular frontend? HOT 3
- Aggregate may change identity during history load HOT 5
- You can no longer return IServiceProvider from ConfigureServices as in Web example from .NET Core 3 HOT 9
- Implement snapshot HOT 4
- DSL for CQRSlite HOT 3
- Service fabric doesn't support GenericHostBuilder HOT 5
- Commands, events and being idempotent? HOT 2
- Entity Framework Problem HOT 6
- Add netstandard2.1 and correct dependencies to match the standards HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cqrslite.