diff --git a/binaries/MongoDB.Bson.dll b/binaries/MongoDB.Bson.dll new file mode 100644 index 0000000..120c5f6 Binary files /dev/null and b/binaries/MongoDB.Bson.dll differ diff --git a/binaries/MongoDB.Driver.dll b/binaries/MongoDB.Driver.dll new file mode 100644 index 0000000..38a728a Binary files /dev/null and b/binaries/MongoDB.Driver.dll differ diff --git a/binaries/SimpleCqrs.EventStore.MongoDb.dll b/binaries/SimpleCqrs.EventStore.MongoDb.dll index beb0ebb..50c18ec 100644 Binary files a/binaries/SimpleCqrs.EventStore.MongoDb.dll and b/binaries/SimpleCqrs.EventStore.MongoDb.dll differ diff --git a/binaries/SimpleCqrs.EventStore.MongoDb.pdb b/binaries/SimpleCqrs.EventStore.MongoDb.pdb index dca293b..ffd8571 100644 Binary files a/binaries/SimpleCqrs.EventStore.MongoDb.pdb and b/binaries/SimpleCqrs.EventStore.MongoDb.pdb differ diff --git a/binaries/SimpleCqrs.Utilites.dll b/binaries/SimpleCqrs.Utilites.dll index 8aad3a6..a1cb54f 100644 Binary files a/binaries/SimpleCqrs.Utilites.dll and b/binaries/SimpleCqrs.Utilites.dll differ diff --git a/binaries/SimpleCqrs.Utilites.pdb b/binaries/SimpleCqrs.Utilites.pdb index d1a8d03..4492663 100644 Binary files a/binaries/SimpleCqrs.Utilites.pdb and b/binaries/SimpleCqrs.Utilites.pdb differ diff --git a/binaries/SimpleCqrs.dll b/binaries/SimpleCqrs.dll index b7800ca..94144bd 100644 Binary files a/binaries/SimpleCqrs.dll and b/binaries/SimpleCqrs.dll differ diff --git a/binaries/SimpleCqrs.pdb b/binaries/SimpleCqrs.pdb index 6d0e3ca..cd0a698 100644 Binary files a/binaries/SimpleCqrs.pdb and b/binaries/SimpleCqrs.pdb differ diff --git a/binaries/eventstores/file/SimpleCqrs.EventStore.File.dll b/binaries/eventstores/file/SimpleCqrs.EventStore.File.dll index c7c93e2..0b3150e 100644 Binary files a/binaries/eventstores/file/SimpleCqrs.EventStore.File.dll and b/binaries/eventstores/file/SimpleCqrs.EventStore.File.dll differ diff --git a/binaries/eventstores/file/SimpleCqrs.EventStore.File.pdb b/binaries/eventstores/file/SimpleCqrs.EventStore.File.pdb index ad2f8f5..da9f1fc 100644 Binary files a/binaries/eventstores/file/SimpleCqrs.EventStore.File.pdb and b/binaries/eventstores/file/SimpleCqrs.EventStore.File.pdb differ diff --git a/binaries/eventstores/mongodb/MongoDB.Bson.dll b/binaries/eventstores/mongodb/MongoDB.Bson.dll new file mode 100644 index 0000000..120c5f6 Binary files /dev/null and b/binaries/eventstores/mongodb/MongoDB.Bson.dll differ diff --git a/binaries/eventstores/mongodb/MongoDB.Driver.dll b/binaries/eventstores/mongodb/MongoDB.Driver.dll new file mode 100644 index 0000000..38a728a Binary files /dev/null and b/binaries/eventstores/mongodb/MongoDB.Driver.dll differ diff --git a/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.dll b/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.dll index beb0ebb..50c18ec 100644 Binary files a/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.dll and b/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.dll differ diff --git a/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.pdb b/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.pdb index dca293b..ffd8571 100644 Binary files a/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.pdb and b/binaries/eventstores/mongodb/SimpleCqrs.EventStore.MongoDb.pdb differ diff --git a/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.dll b/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.dll index b87da1f..a9165c2 100644 Binary files a/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.dll and b/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.dll differ diff --git a/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.pdb b/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.pdb index 6316bfa..64c6cbe 100644 Binary files a/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.pdb and b/binaries/extension/nservicebus/SimpleCqrs.NServiceBus.pdb differ diff --git a/binaries/extension/nservicebus/SimpleCqrs.dll b/binaries/extension/nservicebus/SimpleCqrs.dll index b7800ca..94144bd 100644 Binary files a/binaries/extension/nservicebus/SimpleCqrs.dll and b/binaries/extension/nservicebus/SimpleCqrs.dll differ diff --git a/binaries/extension/nservicebus/SimpleCqrs.pdb b/binaries/extension/nservicebus/SimpleCqrs.pdb index 6d0e3ca..cd0a698 100644 Binary files a/binaries/extension/nservicebus/SimpleCqrs.pdb and b/binaries/extension/nservicebus/SimpleCqrs.pdb differ diff --git a/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.dll b/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.dll index e3652c1..6f216c6 100644 Binary files a/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.dll and b/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.dll differ diff --git a/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.pdb b/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.pdb index bdd99bb..7e308c9 100644 Binary files a/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.pdb and b/binaries/extension/rabbitmq/SimpleCqrs.RabbitMQ.pdb differ diff --git a/binaries/extension/rabbitmq/SimpleCqrs.dll b/binaries/extension/rabbitmq/SimpleCqrs.dll index b7800ca..94144bd 100644 Binary files a/binaries/extension/rabbitmq/SimpleCqrs.dll and b/binaries/extension/rabbitmq/SimpleCqrs.dll differ diff --git a/binaries/extension/rabbitmq/SimpleCqrs.pdb b/binaries/extension/rabbitmq/SimpleCqrs.pdb index 6d0e3ca..cd0a698 100644 Binary files a/binaries/extension/rabbitmq/SimpleCqrs.pdb and b/binaries/extension/rabbitmq/SimpleCqrs.pdb differ diff --git a/binaries/servicelocators/unity/Microsoft.Practices.Unity.dll b/binaries/servicelocators/unity/Microsoft.Practices.Unity.dll index 84f1870..0d1a895 100644 Binary files a/binaries/servicelocators/unity/Microsoft.Practices.Unity.dll and b/binaries/servicelocators/unity/Microsoft.Practices.Unity.dll differ diff --git a/binaries/servicelocators/unity/SimpleCqrs.Unity.dll b/binaries/servicelocators/unity/SimpleCqrs.Unity.dll index 7d2850e..75d2b69 100644 Binary files a/binaries/servicelocators/unity/SimpleCqrs.Unity.dll and b/binaries/servicelocators/unity/SimpleCqrs.Unity.dll differ diff --git a/binaries/servicelocators/unity/SimpleCqrs.Unity.pdb b/binaries/servicelocators/unity/SimpleCqrs.Unity.pdb index b2ed7a7..3b697be 100644 Binary files a/binaries/servicelocators/unity/SimpleCqrs.Unity.pdb and b/binaries/servicelocators/unity/SimpleCqrs.Unity.pdb differ diff --git a/lib/Microsoft.Practices.Unity.dll b/lib/Microsoft.Practices.Unity.dll index 84f1870..0d1a895 100644 Binary files a/lib/Microsoft.Practices.Unity.dll and b/lib/Microsoft.Practices.Unity.dll differ diff --git a/lib/MongoDB.Bson.dll b/lib/MongoDB.Bson.dll new file mode 100644 index 0000000..120c5f6 Binary files /dev/null and b/lib/MongoDB.Bson.dll differ diff --git a/lib/MongoDB.Driver.dll b/lib/MongoDB.Driver.dll new file mode 100644 index 0000000..38a728a Binary files /dev/null and b/lib/MongoDB.Driver.dll differ diff --git a/lib/MongoDB.GridFS.dll b/lib/MongoDB.GridFS.dll deleted file mode 100644 index 24e24fa..0000000 Binary files a/lib/MongoDB.GridFS.dll and /dev/null differ diff --git a/lib/MongoDB.dll b/lib/MongoDB.dll deleted file mode 100644 index 23c4756..0000000 Binary files a/lib/MongoDB.dll and /dev/null differ diff --git a/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoEventStore.cs b/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoEventStore.cs index 0b601e1..055e83e 100644 --- a/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoEventStore.cs +++ b/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoEventStore.cs @@ -1,118 +1,54 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; -using MongoDB; -using MongoDB.Configuration; -using MongoDB.Configuration.Builders; +using MongoDB.Bson; +using MongoDB.Bson.Serialization; +using MongoDB.Driver; +using MongoDB.Driver.Builders; using SimpleCqrs.Eventing; namespace SimpleCqrs.EventStore.MongoDb { public class MongoEventStore : IEventStore { - private static readonly MethodInfo MapMethod = typeof(MappingStoreBuilder).GetMethod("Map", Type.EmptyTypes); - private readonly MongoConfiguration configuration; - private readonly string databaseName; + private readonly MongoCollection _collection; public MongoEventStore(string connectionString, ITypeCatalog typeCatalog) { - var connectionStringBuilder = new MongoConnectionStringBuilder(connectionString); - databaseName = connectionStringBuilder.Database; - configuration = BuildMongoConfiguration(typeCatalog, connectionString); - } - - private static MongoConfiguration BuildMongoConfiguration(ITypeCatalog domainEventTypeCatalog, string connectionString) - { - var configurationBuilder = new MongoConfigurationBuilder(); - configurationBuilder.ConnectionString(connectionString); - configurationBuilder.Mapping(mapping => - { - mapping.DefaultProfile(profile => profile.SubClassesAre(t => t.IsSubclassOf(typeof(DomainEvent)))); - domainEventTypeCatalog - .GetDerivedTypes(typeof(DomainEvent)) - .ToList() - .ForEach(type => MapEventType(type, mapping)); - }); + typeCatalog.GetDerivedTypes(typeof(DomainEvent)).ToList(). + ForEach(x => BsonClassMap.LookupClassMap(x)); - return configurationBuilder.BuildConfiguration(); + _collection = MongoServer.Create(connectionString).GetDatabase("events").GetCollection("events"); } public IEnumerable GetEvents(Guid aggregateRootId, int startSequence) { - using(var mongo = new Mongo(configuration)) - { - mongo.Connect(); - - var database = mongo.GetDatabase(databaseName); - var eventsCollection = database.GetCollection("events").Linq(); - - return (from domainEvent in eventsCollection - where domainEvent.AggregateRootId == aggregateRootId - where domainEvent.Sequence > startSequence - select domainEvent).ToList(); - } + return _collection.Find( + Query.And( + Query.EQ("AggregateRootId", aggregateRootId), + Query.GT("Sequence", startSequence))). + SetFields(Fields.Exclude("_id")).ToList(); } public void Insert(IEnumerable domainEvents) { - using(var mongo = new Mongo(configuration)) - { - mongo.Connect(); - - var database = mongo.GetDatabase(databaseName); - var eventsCollection = database.GetCollection("events"); - eventsCollection.Insert(domainEvents); - } + _collection.InsertBatch(domainEvents); } public IEnumerable GetEventsByEventTypes(IEnumerable domainEventTypes, DateTime startDate, DateTime endDate) { - using(var mongo = new Mongo(configuration)) - { - mongo.Connect(); - - var database = mongo.GetDatabase(databaseName); - var selector = new Document - { - { "_t", new Document { { "$in", domainEventTypes.Select(t => t.Name).ToArray() } } }, - { "EventDate", new Document { { "$gte", startDate }, { "$lte", endDate } } } - }; - - var cursor = database.GetCollection("events").Find(selector); - - return cursor.Documents.ToList(); - } - } - - public IEnumerable GetEventsBySelector(Document selector) - { - using(var mongo = new Mongo(configuration)) - { - mongo.Connect(); - - var database = mongo.GetDatabase(databaseName); - var cursor = database.GetCollection("events").Find(selector); - return cursor.Documents.ToList(); - } + return _collection.Find( + Query.And( + Query.In("_t", domainEventTypes.Select(t => new BsonString(t.Name)).ToArray()), + Query.GTE("EventDate", startDate), + Query.LTE("EventDate", endDate))). + SetFields(Fields.Exclude("_id")).ToList(); } - public IEnumerable GetEventsBySelector(Document selector, int skip, int limit) + public IEnumerable GetEventsBySelector(IMongoQuery selector, int skip, int limit) { - using(var mongo = new Mongo(configuration)) - { - mongo.Connect(); - - var database = mongo.GetDatabase(databaseName); - var cursor = database.GetCollection("events").Find(selector); - return cursor.Skip(skip).Limit(limit).Documents.ToList(); - } + return _collection.Find(selector).SetSkip(skip).SetLimit(limit); } - private static void MapEventType(Type type, MappingStoreBuilder mapping) - { - MapMethod.MakeGenericMethod(type) - .Invoke(mapping, new object[] {}); - } } } \ No newline at end of file diff --git a/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoSnapshotStore.cs b/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoSnapshotStore.cs index 1bd44ca..7096105 100644 --- a/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoSnapshotStore.cs +++ b/src/EventStores/SimpleCqrs.EventStore.MongoDb/MongoSnapshotStore.cs @@ -1,62 +1,34 @@ -using System; -using System.Linq; -using System.Reflection; -using MongoDB; -using MongoDB.Configuration; -using MongoDB.Configuration.Builders; -using SimpleCqrs.Domain; -using SimpleCqrs.Eventing; - -namespace SimpleCqrs.EventStore.MongoDb -{ - public class MongoSnapshotStore : ISnapshotStore - { - private static readonly MethodInfo MapMethod = typeof(MappingStoreBuilder).GetMethod("Map", Type.EmptyTypes); - private readonly IMongoDatabase database; - - public MongoSnapshotStore(string connectionString, ITypeCatalog snapshotTypeCatalog) - { - var configuration = BuildMongoConfiguration(snapshotTypeCatalog, connectionString); - var mongo = new Mongo(configuration); - mongo.Connect(); - - database = mongo.GetDatabase("snapshotstore"); - } - - public Snapshot GetSnapshot(Guid aggregateRootId) - { - var snapshotsCollection = database.GetCollection("snapshots").Linq(); - return (from snapshot in snapshotsCollection - where snapshot.AggregateRootId == aggregateRootId - select snapshot).SingleOrDefault(); - } - - public void SaveSnapshot(TSnapshot snapshot) where TSnapshot : Snapshot - { - var snapshotsCollection = database.GetCollection("snapshots"); - snapshotsCollection.Update(snapshot, new { snapshot.AggregateRootId }, UpdateFlags.Upsert); - } - - private static MongoConfiguration BuildMongoConfiguration(ITypeCatalog snapshotTypeCatalog, string connectionString) - { - var configurationBuilder = new MongoConfigurationBuilder(); - configurationBuilder.ConnectionString(connectionString); - configurationBuilder.Mapping(mapping => - { - mapping.DefaultProfile(profile => profile.SubClassesAre(type => type.IsSubclassOf(typeof(Snapshot)))); - snapshotTypeCatalog - .GetDerivedTypes(typeof(Snapshot)) - .ToList() - .ForEach(type => MapEventType(type, mapping)); - }); - - return configurationBuilder.BuildConfiguration(); - } - - private static void MapEventType(Type type, MappingStoreBuilder mapping) - { - MapMethod.MakeGenericMethod(type) - .Invoke(mapping, new object[] {}); - } - } +using System; +using System.Linq; +using MongoDB.Bson.Serialization; +using MongoDB.Driver; +using MongoDB.Driver.Builders; +using SimpleCqrs.Domain; +using SimpleCqrs.Eventing; + +namespace SimpleCqrs.EventStore.MongoDb +{ + public class MongoSnapshotStore : ISnapshotStore + { + private readonly MongoCollection _collection; + + public MongoSnapshotStore(string connectionString, ITypeCatalog snapshotTypeCatalog) + { + snapshotTypeCatalog.GetDerivedTypes(typeof(Snapshot)).ToList(). + ForEach(x => BsonClassMap.LookupClassMap(x)); + + _collection = MongoServer.Create(connectionString).GetDatabase("snapshotstore").GetCollection("snapshots"); + } + + public Snapshot GetSnapshot(Guid aggregateRootId) + { + return _collection.Find(Query.EQ("AggregateRoootId", aggregateRootId)). + SetFields(Fields.Exclude("_id")).Single(); + } + + public void SaveSnapshot(TSnapshot snapshot) where TSnapshot : Snapshot + { + _collection.Save(snapshot); + } + } } \ No newline at end of file diff --git a/src/EventStores/SimpleCqrs.EventStore.MongoDb/SimpleCqrs.EventStore.MongoDb.csproj b/src/EventStores/SimpleCqrs.EventStore.MongoDb/SimpleCqrs.EventStore.MongoDb.csproj index 71a5c25..0376724 100644 --- a/src/EventStores/SimpleCqrs.EventStore.MongoDb/SimpleCqrs.EventStore.MongoDb.csproj +++ b/src/EventStores/SimpleCqrs.EventStore.MongoDb/SimpleCqrs.EventStore.MongoDb.csproj @@ -32,17 +32,16 @@ 4 - - False - ..\..\..\lib\MongoDB.dll + + ..\..\..\lib\MongoDB.Bson.dll - - False - ..\..\..\lib\MongoDB.GridFS.dll + + ..\..\..\lib\MongoDB.Driver.dll + diff --git a/src/SimpleCQRS.sln b/src/SimpleCQRS.sln index 3d35cdf..16884dd 100644 --- a/src/SimpleCQRS.sln +++ b/src/SimpleCQRS.sln @@ -6,7 +6,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EF3C709C-758C-451D-8B6C-4222D1BE8EDF}" ProjectSection(SolutionItems) = preProject Local.testsettings = Local.testsettings - Simple CQRS.vsmdi = Simple CQRS.vsmdi + SimpleCQRS.vsmdi = SimpleCQRS.vsmdi TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings EndProjectSection EndProject @@ -38,7 +38,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleCqrs.RabbitMQ", "Exte EndProject Global GlobalSection(TestCaseManagementSettings) = postSolution - CategoryFile = Simple CQRS.vsmdi + CategoryFile = SimpleCQRS.vsmdi EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -90,7 +90,6 @@ Global {D3DFE07B-B78C-4AF2-A886-002A09D9FAA0} = {BE8A5F95-23AD-4B5D-BA21-004909E80F00} {201A4DF5-2217-4202-80E8-E784737366BC} = {77CC485D-D260-45FC-A161-3DDF3A571C41} {65B52205-E45D-4D6B-8F48-AFBC4406BEE8} = {77CC485D-D260-45FC-A161-3DDF3A571C41} - {BEEBFC8E-91EC-4E24-8223-395C2302C1B3} = {77CC485D-D260-45FC-A161-3DDF3A571C41} {38E51E8F-7008-47EC-AC9F-862A1F377532} = {D3DFE07B-B78C-4AF2-A886-002A09D9FAA0} {00634E6C-A282-404A-B08B-338FD4CA41A9} = {0C8AE82D-CACF-44CD-BE4F-222041AC4699} {07C2BF77-9646-4C39-BDB2-852B76AA6C75} = {51C20E77-8726-49E8-9061-161DF28973E7} diff --git a/src/SimpleCQRS.vsmdi b/src/SimpleCQRS.vsmdi new file mode 100644 index 0000000..752f0c9 --- /dev/null +++ b/src/SimpleCQRS.vsmdi @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/SimpleCqrs.Utilites/SimpleCqrs.Utilites.csproj b/src/SimpleCqrs.Utilites/SimpleCqrs.Utilites.csproj index dc2de81..1b7e9fc 100644 --- a/src/SimpleCqrs.Utilites/SimpleCqrs.Utilites.csproj +++ b/src/SimpleCqrs.Utilites/SimpleCqrs.Utilites.csproj @@ -31,9 +31,6 @@ 4 - - ..\..\lib\MongoDB.dll -