From 269b32ed32a39acb06d5670f88d3178fbb9e2f10 Mon Sep 17 00:00:00 2001 From: Greg Munn Date: Sun, 7 Oct 2012 17:23:38 +1100 Subject: [PATCH] Just lots more tiding. --- MonoKit.Domain/DomainContext.cs | 8 +- MonoKit.Domain/DomainEvent_T.cs | 33 ------- MonoKit.Domain/EventExtensions.cs | 8 +- .../EventSourcedAggregateRepository_T.cs | 4 +- MonoKit.Domain/IAggregateEvent.cs | 2 +- MonoKit.Domain/IDomainContext.cs | 6 +- MonoKit.Domain/IReadModelBuilder.cs | 2 +- MonoKit.Domain/MonoKit.Domain.csproj | 7 +- .../NotificationEventBusExtensions.cs | 80 +++++++++++++++ MonoKit.Domain/ObservableDomainEventBus.cs | 98 ------------------- .../ObservableNotificationEventBus.cs | 46 +++++++++ MonoKit.Domain/ReadModelBuilder.cs | 10 +- MonoKit.Domain/ReadModelBuildingEventBus_T.cs | 14 +-- .../SnapshotAggregateRepository_T.cs | 16 +-- MonoKit.Domain/UnitOfWorkEventBus.cs | 14 +-- MonoKit.iOS/Data/SQLite/SqlRepository_T.cs | 16 +-- MonoKit.iOS/Domain/SQLite/SqlDomainContext.cs | 2 +- ...{DataModelChange.cs => DataChangeEvent.cs} | 28 +++--- ...aModelChange_T.cs => DataChangeEvent_T.cs} | 8 +- ...taModelChangeKind.cs => DataChangeKind.cs} | 4 +- ...DataModelChange.cs => IDataChangeEvent.cs} | 12 +-- MonoKit/Data/IDataModelEventBus.cs | 30 ------ MonoKit/Data/IObservableRepository.cs | 3 +- MonoKit/{Data/IEvent.cs => INotification.cs} | 7 +- .../INotificationEvent.cs | 13 ++- .../INotificationEventBus.cs | 6 +- MonoKit/MonoKit.csproj | 14 +-- .../NotificationEvent.cs | 15 ++- .../Domain/EventSourceSamples.cs | 2 +- Samples/MonoKitSample/Domain/SampleDomain.cs | 3 +- .../MonoKitSample/Domain/SnapshotSamples.cs | 2 +- 31 files changed, 237 insertions(+), 276 deletions(-) delete mode 100644 MonoKit.Domain/DomainEvent_T.cs create mode 100644 MonoKit.Domain/NotificationEventBusExtensions.cs delete mode 100644 MonoKit.Domain/ObservableDomainEventBus.cs create mode 100644 MonoKit.Domain/ObservableNotificationEventBus.cs rename MonoKit/Data/{DataModelChange.cs => DataChangeEvent.cs} (65%) rename MonoKit/Data/{DataModelChange_T.cs => DataChangeEvent_T.cs} (85%) rename MonoKit/Data/{DataModelChangeKind.cs => DataChangeKind.cs} (93%) rename MonoKit/Data/{IDataModelChange.cs => IDataChangeEvent.cs} (84%) delete mode 100644 MonoKit/Data/IDataModelEventBus.cs rename MonoKit/{Data/IEvent.cs => INotification.cs} (92%) rename MonoKit.Domain/IDomainEvent.cs => MonoKit/INotificationEvent.cs (84%) rename MonoKit.Domain/IDomainEventBus.cs => MonoKit/INotificationEventBus.cs (91%) rename MonoKit.Domain/DomainEvent.cs => MonoKit/NotificationEvent.cs (82%) diff --git a/MonoKit.Domain/DomainContext.cs b/MonoKit.Domain/DomainContext.cs index 53f9f0e..dc9fd07 100644 --- a/MonoKit.Domain/DomainContext.cs +++ b/MonoKit.Domain/DomainContext.cs @@ -31,7 +31,7 @@ public abstract class DomainContext : IDomainContext private readonly Dictionary> registeredSnapshotRepositories; - public DomainContext(IAggregateManifestRepository manifest, IEventStoreRepository eventStore, IDomainEventBus eventBus) + public DomainContext(IAggregateManifestRepository manifest, IEventStoreRepository eventStore, INotificationEventBus eventBus) { this.Manifest = manifest; this.EventBus = eventBus; @@ -45,7 +45,7 @@ public DomainContext(IAggregateManifestRepository manifest, IEventStoreRepositor public IEventStoreRepository EventStore { get; private set; } - public IDomainEventBus EventBus { get; private set; } + public INotificationEventBus EventBus { get; private set; } public IEventSerializer EventSerializer { get; protected set; } @@ -59,7 +59,7 @@ public virtual IUnitOfWorkScope BeginUnitOfWork() return new DomainCommandExecutor(this); } - public virtual IAggregateRepository GetAggregateRepository(IDomainEventBus bus) where T : IAggregateRoot, new() + public virtual IAggregateRepository GetAggregateRepository(INotificationEventBus bus) where T : IAggregateRoot, new() { if (typeof(T).GetInterfaces().Contains(typeof(IEventSourced))) { @@ -76,7 +76,7 @@ public virtual IUnitOfWorkScope BeginUnitOfWork() return repo; } - public IList GetReadModelBuilders(IDomainEventBus bus) where T : IAggregateRoot, new() + public IList GetReadModelBuilders(INotificationEventBus bus) where T : IAggregateRoot, new() { var result = new List(); diff --git a/MonoKit.Domain/DomainEvent_T.cs b/MonoKit.Domain/DomainEvent_T.cs deleted file mode 100644 index 082de7c..0000000 --- a/MonoKit.Domain/DomainEvent_T.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) sgmunn 2012 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and -// to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of -// the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace MonoKit.Domain -{ - using System; - using MonoKit.Data; - - public sealed class DomainEvent : DomainEvent - { - public DomainEvent(Guid id, IEvent evt) - : base(typeof(T), id, evt) - { - } - } -} diff --git a/MonoKit.Domain/EventExtensions.cs b/MonoKit.Domain/EventExtensions.cs index fb0d766..11bbc5f 100644 --- a/MonoKit.Domain/EventExtensions.cs +++ b/MonoKit.Domain/EventExtensions.cs @@ -25,14 +25,14 @@ namespace MonoKit.Domain public static class EventExtensions { - public static IDomainEvent AsDomainEvent(this IDataModelChange modelChange) + public static INotificationEvent AsDomainEvent(this IDataChangeEvent dataChange) { - return new DomainEvent(modelChange.DataModelType, modelChange.DataModelId, modelChange); + return new NotificationEvent(dataChange.DataType, dataChange.DataId, dataChange); } - public static IDomainEvent AsDomainEvent(this IAggregateEvent aggregateEvent, Type aggregateType) + public static INotificationEvent AsDomainEvent(this IAggregateEvent aggregateEvent, Type aggregateType) { - return new DomainEvent(aggregateType, aggregateEvent.AggregateId, aggregateEvent); + return new NotificationEvent(aggregateType, aggregateEvent.AggregateId, aggregateEvent); } } } diff --git a/MonoKit.Domain/EventSourcedAggregateRepository_T.cs b/MonoKit.Domain/EventSourcedAggregateRepository_T.cs index 3134f40..4dc46af 100644 --- a/MonoKit.Domain/EventSourcedAggregateRepository_T.cs +++ b/MonoKit.Domain/EventSourcedAggregateRepository_T.cs @@ -34,9 +34,9 @@ namespace MonoKit.Domain private readonly IAggregateManifestRepository manifest; - private readonly IDomainEventBus eventBus; + private readonly INotificationEventBus eventBus; - public EventSourcedAggregateRepository(IEventSerializer serializer, IEventStoreRepository repository, IAggregateManifestRepository manifest, IDomainEventBus eventBus) + public EventSourcedAggregateRepository(IEventSerializer serializer, IEventStoreRepository repository, IAggregateManifestRepository manifest, INotificationEventBus eventBus) { this.serializer = serializer; this.repository = repository; diff --git a/MonoKit.Domain/IAggregateEvent.cs b/MonoKit.Domain/IAggregateEvent.cs index b2f89da..247be31 100644 --- a/MonoKit.Domain/IAggregateEvent.cs +++ b/MonoKit.Domain/IAggregateEvent.cs @@ -23,7 +23,7 @@ namespace MonoKit.Domain using System; using MonoKit.Data; - public interface IAggregateEvent : IId, IEvent + public interface IAggregateEvent : IId, INotification { Guid AggregateId { get; set; } diff --git a/MonoKit.Domain/IDomainContext.cs b/MonoKit.Domain/IDomainContext.cs index acfd786..2f6f1a5 100644 --- a/MonoKit.Domain/IDomainContext.cs +++ b/MonoKit.Domain/IDomainContext.cs @@ -28,7 +28,7 @@ public interface IDomainContext { IEventStoreRepository EventStore { get; } - IDomainEventBus EventBus { get; } + INotificationEventBus EventBus { get; } IEventSerializer EventSerializer { get; } @@ -36,9 +36,9 @@ public interface IDomainContext ICommandExecutor NewCommandExecutor() where T : class, IAggregateRoot, new(); - IAggregateRepository GetAggregateRepository(IDomainEventBus bus) where T : IAggregateRoot, new(); + IAggregateRepository GetAggregateRepository(INotificationEventBus bus) where T : IAggregateRoot, new(); - IList GetReadModelBuilders(IDomainEventBus bus) where T : IAggregateRoot, new(); + IList GetReadModelBuilders(INotificationEventBus bus) where T : IAggregateRoot, new(); } } diff --git a/MonoKit.Domain/IReadModelBuilder.cs b/MonoKit.Domain/IReadModelBuilder.cs index e6dcbad..971556c 100644 --- a/MonoKit.Domain/IReadModelBuilder.cs +++ b/MonoKit.Domain/IReadModelBuilder.cs @@ -26,6 +26,6 @@ namespace MonoKit.Domain public interface IReadModelBuilder { - IEnumerable Handle(IDomainEvent evt); + IEnumerable Handle(INotificationEvent evt); } } diff --git a/MonoKit.Domain/MonoKit.Domain.csproj b/MonoKit.Domain/MonoKit.Domain.csproj index 196fe2a..7a75ea9 100644 --- a/MonoKit.Domain/MonoKit.Domain.csproj +++ b/MonoKit.Domain/MonoKit.Domain.csproj @@ -53,8 +53,6 @@ - - @@ -65,8 +63,6 @@ - - @@ -77,10 +73,11 @@ - + + \ No newline at end of file diff --git a/MonoKit.Domain/NotificationEventBusExtensions.cs b/MonoKit.Domain/NotificationEventBusExtensions.cs new file mode 100644 index 0000000..4e6a15d --- /dev/null +++ b/MonoKit.Domain/NotificationEventBusExtensions.cs @@ -0,0 +1,80 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// (c) sgmunn 2012 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +// to permit persons to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of +// the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace MonoKit.Domain +{ + using System; + using MonoKit.Reactive.Subjects; + using MonoKit.Data; + using MonoKit.Reactive.Linq; + + public static class NotificationEventBusExtensions + { + /// + /// Returns IDataModelEvents that are for the specified identity type. These could be events or read model changes + /// +// public static IObservable ForIdentity(this IObservable source) +// { +// //return source.Where (x => x != null && typeof(T).IsAssignableFrom(x.Identity.GetType())); +// return source.Where(x => x.DataModelType is T); +// } +// +// /// +// /// Returns data model changes for the given identity, events or read models +// /// +// public static IObservable DataModelChangesForIdentity(this IObservable source) where T : IUniqueIdentity +// { +// return source.ForIdentity() +// .OfType(); +// } +// +// /// +// /// Returns events for the given identity type +// /// +// public static IObservable EventsForIdentity(this IObservable source) where T : IUniqueIdentity +// { +// return source.ForIdentity() +// .OfType(); +// } + + /// + /// Returns data model changes for the specified read model type, excluding deleted read models + /// + public static IObservable DataModelChangesForType(this IObservable source) + { + return source.Select(x => x.Event) + .OfType() + //.Where (x => x != null && x.Change != DataModelChangeKind.Deleted && typeof(T).IsAssignableFrom(x.DataModel.GetType())) + .Where (x => x != null && x.Change != DataChangeKind.Deleted && x.Data is T) + .Select(x => (T)x.Data); + } + + /// + /// Returns delete notifications for read models of the specified identity type + /// +// public static IObservable DataModelDeletionsForIdentity(this IObservable source) where T : IUniqueIdentity +// { +// return source.ForIdentity() +// .OfType() +// .Where(x => x.Deleted) +// .Select(x => x.Identity); +// } + } +} diff --git a/MonoKit.Domain/ObservableDomainEventBus.cs b/MonoKit.Domain/ObservableDomainEventBus.cs deleted file mode 100644 index eff78f9..0000000 --- a/MonoKit.Domain/ObservableDomainEventBus.cs +++ /dev/null @@ -1,98 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) sgmunn 2012 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and -// to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of -// the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace MonoKit.Domain -{ - using System; - using MonoKit.Reactive.Subjects; - using MonoKit.Data; - using MonoKit.Reactive.Linq; - - public sealed class ObservableDomainEventBus : IDomainEventBus - { - private readonly Subject eventPublisher; - - public ObservableDomainEventBus() - { - this.eventPublisher = new Subject(); - } - - public void Publish(IDomainEvent evt) - { - this.eventPublisher.OnNext(evt); - } - - public IDisposable Subscribe(IObserver observer) - { - return this.eventPublisher.Subscribe(observer); - } - } - - public static class EventBusExtensions - { - /// - /// Returns IDataModelEvents that are for the specified identity type. These could be events or read model changes - /// -// public static IObservable ForIdentity(this IObservable source) where T : IUniqueIdentity -// { -// return source.Where (x => x != null && typeof(T).IsAssignableFrom(x.Identity.GetType())); -// } -// -// /// -// /// Returns data model changes for the given identity, events or read models -// /// -// public static IObservable DataModelChangesForIdentity(this IObservable source) where T : IUniqueIdentity -// { -// return source.ForIdentity() -// .OfType(); -// } -// -// /// -// /// Returns events for the given identity type -// /// -// public static IObservable EventsForIdentity(this IObservable source) where T : IUniqueIdentity -// { -// return source.ForIdentity() -// .OfType(); -// } - - /// - /// Returns data model changes for the specified read model type, excluding deleted read models - /// - public static IObservable DataModelChangesForType(this IObservable source) - { - return source.OfType() - .Where (x => x != null && x.Change != DataModelChangeKind.Deleted && typeof(T).IsAssignableFrom(x.DataModel.GetType())) - .Select(x => (T)x.DataModel); - } - - /// - /// Returns delete notifications for read models of the specified identity type - /// -// public static IObservable DataModelDeletionsForIdentity(this IObservable source) where T : IUniqueIdentity -// { -// return source.ForIdentity() -// .OfType() -// .Where(x => x.Deleted) -// .Select(x => x.Identity); -// } - } -} - diff --git a/MonoKit.Domain/ObservableNotificationEventBus.cs b/MonoKit.Domain/ObservableNotificationEventBus.cs new file mode 100644 index 0000000..dc2ad14 --- /dev/null +++ b/MonoKit.Domain/ObservableNotificationEventBus.cs @@ -0,0 +1,46 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// (c) sgmunn 2012 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +// to permit persons to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of +// the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace MonoKit.Domain +{ + using System; + using MonoKit.Reactive.Subjects; + + public sealed class ObservableNotificationEventBus : INotificationEventBus + { + private readonly Subject eventPublisher; + + public ObservableNotificationEventBus() + { + this.eventPublisher = new Subject(); + } + + public void Publish(INotificationEvent evt) + { + this.eventPublisher.OnNext(evt); + } + + public IDisposable Subscribe(IObserver observer) + { + return this.eventPublisher.Subscribe(observer); + } + } +} + diff --git a/MonoKit.Domain/ReadModelBuilder.cs b/MonoKit.Domain/ReadModelBuilder.cs index 6a835f7..6ace1f2 100644 --- a/MonoKit.Domain/ReadModelBuilder.cs +++ b/MonoKit.Domain/ReadModelBuilder.cs @@ -28,14 +28,14 @@ public abstract class ReadModelBuilder : IReadModelBuilder, IObservableRep { private readonly IRepository repository; - private readonly List updatedReadModels; + private readonly List updatedReadModels; - private readonly IObservable changes; + private readonly IObservable changes; protected ReadModelBuilder(IRepository repository) { this.repository = repository; - this.updatedReadModels = new List(); + this.updatedReadModels = new List(); var observableRepo = repository as IObservableRepository; this.changes = observableRepo != null ? observableRepo.Changes : null; @@ -49,7 +49,7 @@ public IRepository Repository } } - public IEnumerable Handle(IDomainEvent evt) + public IEnumerable Handle(INotificationEvent evt) { this.updatedReadModels.Clear(); @@ -61,7 +61,7 @@ public IEnumerable Handle(IDomainEvent evt) return this.updatedReadModels; } - public IObservable Changes + public IObservable Changes { get { diff --git a/MonoKit.Domain/ReadModelBuildingEventBus_T.cs b/MonoKit.Domain/ReadModelBuildingEventBus_T.cs index 63b12bc..fff59f1 100644 --- a/MonoKit.Domain/ReadModelBuildingEventBus_T.cs +++ b/MonoKit.Domain/ReadModelBuildingEventBus_T.cs @@ -25,20 +25,20 @@ namespace MonoKit.Domain using MonoKit.Data; // todo: change from T to pass in the registerd builders - public class ReadModelBuildingEventBus : IDomainEventBus + public class ReadModelBuildingEventBus : INotificationEventBus where T : IAggregateRoot, new() { private readonly IDomainContext context; - private readonly IDomainEventBus bus; + private readonly INotificationEventBus bus; - public ReadModelBuildingEventBus(IDomainContext context, IDomainEventBus bus) + public ReadModelBuildingEventBus(IDomainContext context, INotificationEventBus bus) { this.context = context; this.bus = bus; } - public void Publish(IDomainEvent evt) + public void Publish(INotificationEvent evt) { if (this.bus != null) { @@ -47,7 +47,7 @@ public void Publish(IDomainEvent evt) var builders = this.context.GetReadModelBuilders(this.bus); - var updatedReadModels = new List(); + var updatedReadModels = new List(); // todo: this coud be done async, but because we should only have one thread to the db at any one time it's not really worth it. // just don't take too long in any one builder and don't make assumptions on the order of builders being executed. @@ -60,12 +60,12 @@ public void Publish(IDomainEvent evt) { foreach (var readModel in updatedReadModels) { - this.bus.Publish(new DomainEvent(readModel.DataModelType, readModel.DataModelId, readModel)); + this.bus.Publish(new NotificationEvent(readModel.DataType, readModel.DataId, readModel)); } } } - public IDisposable Subscribe(IObserver subscriber) + public IDisposable Subscribe(IObserver subscriber) { throw new NotSupportedException(); } diff --git a/MonoKit.Domain/SnapshotAggregateRepository_T.cs b/MonoKit.Domain/SnapshotAggregateRepository_T.cs index b7aef29..f61eee9 100644 --- a/MonoKit.Domain/SnapshotAggregateRepository_T.cs +++ b/MonoKit.Domain/SnapshotAggregateRepository_T.cs @@ -35,18 +35,18 @@ public class SnapshotAggregateRepository : IAggregateRepository, IObservab { private readonly ISnapshotRepository repository; - private readonly IDomainEventBus eventBus; + private readonly INotificationEventBus eventBus; private readonly IAggregateManifestRepository manifest; - private readonly Subject changes; + private readonly Subject changes; - public SnapshotAggregateRepository(ISnapshotRepository repository, IAggregateManifestRepository manifest, IDomainEventBus eventBus) + public SnapshotAggregateRepository(ISnapshotRepository repository, IAggregateManifestRepository manifest, INotificationEventBus eventBus) { this.repository = repository; this.eventBus = eventBus; this.manifest = manifest; - this.changes = new Subject(); + this.changes = new Subject(); } public T New() @@ -97,14 +97,14 @@ public SaveResult Save(T instance) var saveResult = this.repository.Save(snapshot); - IDataModelChange modelChange = null; + IDataChangeEvent modelChange = null; switch (saveResult) { case SaveResult.Added: - modelChange = new DataModelChange(snapshot.GetType(), snapshot.Identity, snapshot, DataModelChangeKind.Added); + modelChange = new DataChangeEvent(snapshot.GetType(), snapshot.Identity, snapshot, DataChangeKind.Added); break; case SaveResult.Updated: - modelChange = new DataModelChange(snapshot.GetType(), snapshot.Identity, snapshot, DataModelChangeKind.Changed); + modelChange = new DataChangeEvent(snapshot.GetType(), snapshot.Identity, snapshot, DataChangeKind.Changed); break; } @@ -131,7 +131,7 @@ public void Dispose() this.repository.Dispose(); } - public IObservable Changes + public IObservable Changes { get { diff --git a/MonoKit.Domain/UnitOfWorkEventBus.cs b/MonoKit.Domain/UnitOfWorkEventBus.cs index ff94d54..f846f89 100644 --- a/MonoKit.Domain/UnitOfWorkEventBus.cs +++ b/MonoKit.Domain/UnitOfWorkEventBus.cs @@ -24,24 +24,24 @@ namespace MonoKit.Domain using System.Collections.Generic; using MonoKit.Data; - public class UnitOfWorkEventBus : IDomainEventBus, IUnitOfWork + public class UnitOfWorkEventBus : INotificationEventBus, IUnitOfWork { - private readonly IDomainEventBus bus; + private readonly INotificationEventBus bus; - private readonly List events; + private readonly List events; - public UnitOfWorkEventBus(IDomainEventBus bus) + public UnitOfWorkEventBus(INotificationEventBus bus) { - this.events = new List(); + this.events = new List(); this.bus = bus; } - public void Publish(IDomainEvent evt) + public void Publish(INotificationEvent evt) { this.events.Add(evt); } - public IDisposable Subscribe(IObserver subscriber) + public IDisposable Subscribe(IObserver subscriber) { throw new NotSupportedException(); } diff --git a/MonoKit.iOS/Data/SQLite/SqlRepository_T.cs b/MonoKit.iOS/Data/SQLite/SqlRepository_T.cs index 86744b5..754053b 100644 --- a/MonoKit.iOS/Data/SQLite/SqlRepository_T.cs +++ b/MonoKit.iOS/Data/SQLite/SqlRepository_T.cs @@ -34,12 +34,12 @@ public class SqlRepository : IRepository, IConnectedRepository, IObservabl { private readonly SQLiteConnection connection; - private readonly Subject changes; + private readonly Subject changes; public SqlRepository(SQLiteConnection connection) { this.connection = connection; - this.changes = new Subject(); + this.changes = new Subject(); } object IConnectedRepository.Connection @@ -50,7 +50,7 @@ object IConnectedRepository.Connection } } - public IObservable Changes + public IObservable Changes { get { @@ -111,14 +111,14 @@ public virtual SaveResult Save(T instance) } }); - IDataModelChange modelChange = null; + IDataChangeEvent modelChange = null; switch (result) { case SaveResult.Added: - modelChange = new DataModelChange(instance.Identity, instance, DataModelChangeKind.Added); + modelChange = new DataChangeEvent(instance.Identity, instance, DataChangeKind.Added); break; case SaveResult.Updated: - modelChange = new DataModelChange(instance.Identity, instance, DataModelChangeKind.Changed); + modelChange = new DataChangeEvent(instance.Identity, instance, DataChangeKind.Changed); break; } @@ -130,7 +130,7 @@ public virtual SaveResult Save(T instance) public virtual void Delete(T instance) { SynchronousTask.DoSync(() => this.Connection.Delete(instance)); - var modelChange = new DataModelChange(instance.Identity, DataModelChangeKind.Deleted); + var modelChange = new DataChangeEvent(instance.Identity, DataChangeKind.Deleted); this.changes.OnNext(modelChange); } @@ -148,7 +148,7 @@ public virtual void DeleteId(Guid id) var q = string.Format ("delete from \"{0}\" where \"{1}\" = ?", map.TableName, pk.Name); this.Connection.Execute (q, id); - var modelChange = new DataModelChange(id, DataModelChangeKind.Deleted); + var modelChange = new DataChangeEvent(id, DataChangeKind.Deleted); this.changes.OnNext(modelChange); }); } diff --git a/MonoKit.iOS/Domain/SQLite/SqlDomainContext.cs b/MonoKit.iOS/Domain/SQLite/SqlDomainContext.cs index 6fc3102..62a3976 100644 --- a/MonoKit.iOS/Domain/SQLite/SqlDomainContext.cs +++ b/MonoKit.iOS/Domain/SQLite/SqlDomainContext.cs @@ -27,7 +27,7 @@ namespace MonoKit.Domain.SQLite public class SqlDomainContext : DomainContext { - public SqlDomainContext(SQLiteConnection connection, IAggregateManifestRepository manifest, IEventStoreRepository eventStore, IDomainEventBus eventBus) : + public SqlDomainContext(SQLiteConnection connection, IAggregateManifestRepository manifest, IEventStoreRepository eventStore, INotificationEventBus eventBus) : base(manifest, eventStore, eventBus) { this.Connection = connection; diff --git a/MonoKit/Data/DataModelChange.cs b/MonoKit/Data/DataChangeEvent.cs similarity index 65% rename from MonoKit/Data/DataModelChange.cs rename to MonoKit/Data/DataChangeEvent.cs index fb7dab4..4136a82 100644 --- a/MonoKit/Data/DataModelChange.cs +++ b/MonoKit/Data/DataChangeEvent.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // (c) sgmunn 2012 // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -22,34 +22,34 @@ namespace MonoKit.Data { using System; - public class DataModelChange : IDataModelChange + public class DataChangeEvent : IDataChangeEvent { - public DataModelChange(Type dataModelType, Guid id, object dataModel, DataModelChangeKind change) + public DataChangeEvent(Type dataType, Guid id, object data, DataChangeKind change) { - this.DataModel = dataModel; - this.DataModelId = id; + this.Data = data; + this.DataId = id; this.Change = change; - this.DataModelType = dataModelType; + this.DataType = dataType; } - public DataModelChange(Type dataModelType, Guid id, DataModelChangeKind change) + public DataChangeEvent(Type dataType, Guid id, DataChangeKind change) { - this.DataModelId = id; + this.DataId = id; this.Change = change; - this.DataModelType = dataModelType; + this.DataType = dataType; } - public Guid DataModelId { get; set; } + public Guid DataId { get; set; } - public Type DataModelType { get; set; } + public Type DataType { get; set; } - public object DataModel { get; private set; } + public object Data { get; private set; } - public DataModelChangeKind Change { get; private set; } + public DataChangeKind Change { get; private set; } public override string ToString() { - return string.Format("[DataModelChange: Type = {0}, Id={1}, Change={2}, DataModel={3}]", DataModelType, DataModelId, Change, DataModel); + return string.Format("[DataChange: Type = {0}, Id={1}, Change={2}, Data={3}]", DataType, DataId, Change, Data); } } } diff --git a/MonoKit/Data/DataModelChange_T.cs b/MonoKit/Data/DataChangeEvent_T.cs similarity index 85% rename from MonoKit/Data/DataModelChange_T.cs rename to MonoKit/Data/DataChangeEvent_T.cs index 642b22a..1d56f07 100644 --- a/MonoKit/Data/DataModelChange_T.cs +++ b/MonoKit/Data/DataChangeEvent_T.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // (c) sgmunn 2012 // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -22,14 +22,14 @@ namespace MonoKit.Data { using System; - public class DataModelChange : DataModelChange + public class DataChangeEvent : DataChangeEvent { - public DataModelChange(Guid id, object dataModel, DataModelChangeKind change) + public DataChangeEvent(Guid id, object dataModel, DataChangeKind change) : base(typeof(T), id, dataModel, change) { } - public DataModelChange(Guid id, DataModelChangeKind change) + public DataChangeEvent(Guid id, DataChangeKind change) : base(typeof(T), id, change) { } diff --git a/MonoKit/Data/DataModelChangeKind.cs b/MonoKit/Data/DataChangeKind.cs similarity index 93% rename from MonoKit/Data/DataModelChangeKind.cs rename to MonoKit/Data/DataChangeKind.cs index 8c9c537..9d86aac 100644 --- a/MonoKit/Data/DataModelChangeKind.cs +++ b/MonoKit/Data/DataChangeKind.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // (c) sgmunn 2012 // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -22,7 +22,7 @@ namespace MonoKit.Data { using System; - public enum DataModelChangeKind + public enum DataChangeKind { Added, Changed, diff --git a/MonoKit/Data/IDataModelChange.cs b/MonoKit/Data/IDataChangeEvent.cs similarity index 84% rename from MonoKit/Data/IDataModelChange.cs rename to MonoKit/Data/IDataChangeEvent.cs index b0dbc75..4850d21 100644 --- a/MonoKit/Data/IDataModelChange.cs +++ b/MonoKit/Data/IDataChangeEvent.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // (c) sgmunn 2012 // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -22,14 +22,14 @@ namespace MonoKit.Data { using System; - public interface IDataModelChange : IEvent + public interface IDataChangeEvent : INotification { - Guid DataModelId { get; set; } + Guid DataId { get; set; } - Type DataModelType { get; set; } + Type DataType { get; set; } - object DataModel { get; } + object Data { get; } - DataModelChangeKind Change { get; } + DataChangeKind Change { get; } } } diff --git a/MonoKit/Data/IDataModelEventBus.cs b/MonoKit/Data/IDataModelEventBus.cs deleted file mode 100644 index 9c1581b..0000000 --- a/MonoKit/Data/IDataModelEventBus.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) sgmunn 2012 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and -// to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of -// the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// -// -------------------------------------------------------------------------------------------------------------------- -// - -namespace MonoKit.Domain.Data -{ - using System; - -// public interface IDataModelEventBus -// { -// void Publish(IDomainEvent evt); -// } -} diff --git a/MonoKit/Data/IObservableRepository.cs b/MonoKit/Data/IObservableRepository.cs index f704ab9..93cc372 100644 --- a/MonoKit/Data/IObservableRepository.cs +++ b/MonoKit/Data/IObservableRepository.cs @@ -17,7 +17,6 @@ // IN THE SOFTWARE. // // -------------------------------------------------------------------------------------------------------------------- -using MonoKit.Domain; namespace MonoKit.Data { @@ -25,7 +24,7 @@ namespace MonoKit.Data public interface IObservableRepository { - IObservable Changes { get; } + IObservable Changes { get; } } } diff --git a/MonoKit/Data/IEvent.cs b/MonoKit/INotification.cs similarity index 92% rename from MonoKit/Data/IEvent.cs rename to MonoKit/INotification.cs index ffb8858..f7c1e49 100644 --- a/MonoKit/Data/IEvent.cs +++ b/MonoKit/INotification.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // (c) sgmunn 2012 // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -18,12 +18,11 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace MonoKit.Data +namespace MonoKit { using System; - public interface IEvent + public interface INotification { } - } diff --git a/MonoKit.Domain/IDomainEvent.cs b/MonoKit/INotificationEvent.cs similarity index 84% rename from MonoKit.Domain/IDomainEvent.cs rename to MonoKit/INotificationEvent.cs index 6aeaaa2..421c7bc 100644 --- a/MonoKit.Domain/IDomainEvent.cs +++ b/MonoKit/INotificationEvent.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // (c) sgmunn 2012 // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -18,17 +18,16 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace MonoKit.Domain +namespace MonoKit { using System; - using MonoKit.Data; - public interface IDomainEvent + public interface INotificationEvent { - Guid DataModelId { get; set; } + Guid DataModelId { get; } - Type DataModelType { get; set; } + Type DataModelType { get; } - IEvent Event { get; set; } + INotification Event { get; } } } diff --git a/MonoKit.Domain/IDomainEventBus.cs b/MonoKit/INotificationEventBus.cs similarity index 91% rename from MonoKit.Domain/IDomainEventBus.cs rename to MonoKit/INotificationEventBus.cs index b0edc0c..95283df 100644 --- a/MonoKit.Domain/IDomainEventBus.cs +++ b/MonoKit/INotificationEventBus.cs @@ -18,13 +18,13 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace MonoKit.Domain +namespace MonoKit { using System; - public interface IDomainEventBus : IObservable + public interface INotificationEventBus : IObservable { - void Publish(IDomainEvent evt); + void Publish(INotificationEvent evt); } } diff --git a/MonoKit/MonoKit.csproj b/MonoKit/MonoKit.csproj index 9faf8ed..0b5dc64 100644 --- a/MonoKit/MonoKit.csproj +++ b/MonoKit/MonoKit.csproj @@ -85,8 +85,6 @@ - - @@ -97,10 +95,14 @@ - - - - + + + + + + + + \ No newline at end of file diff --git a/MonoKit.Domain/DomainEvent.cs b/MonoKit/NotificationEvent.cs similarity index 82% rename from MonoKit.Domain/DomainEvent.cs rename to MonoKit/NotificationEvent.cs index 2006bdd..f6717b3 100644 --- a/MonoKit.Domain/DomainEvent.cs +++ b/MonoKit/NotificationEvent.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // (c) sgmunn 2012 // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -18,25 +18,24 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace MonoKit.Domain +namespace MonoKit { using System; - using MonoKit.Data; - public class DomainEvent : IDomainEvent + public sealed class NotificationEvent : INotificationEvent { - public DomainEvent(Type type, Guid id, IEvent evt ) + public NotificationEvent(Type type, Guid id, INotification evt ) { this.DataModelId = id; this.DataModelType = type; this.Event = evt; } - public Guid DataModelId { get; set; } + public Guid DataModelId { get; private set; } - public Type DataModelType { get; set; } + public Type DataModelType { get; private set; } - public IEvent Event { get; set; } + public INotification Event { get; private set; } public override string ToString() { diff --git a/Samples/MonoKitSample/Domain/EventSourceSamples.cs b/Samples/MonoKitSample/Domain/EventSourceSamples.cs index 22fa87b..f82aa06 100644 --- a/Samples/MonoKitSample/Domain/EventSourceSamples.cs +++ b/Samples/MonoKitSample/Domain/EventSourceSamples.cs @@ -40,7 +40,7 @@ public static IDomainContext GetDomainContext() var eventStore = new EventStoreRepository(EventSourcedDB.Main); - var domainBus = new ObservableDomainEventBus(); + var domainBus = new ObservableNotificationEventBus(); domainBus.Subscribe((x) => Console.WriteLine("domain bus event {0}", x)); var context = new TestDomainContext(EventSourcedDB.Main, manifest, eventStore, domainBus); diff --git a/Samples/MonoKitSample/Domain/SampleDomain.cs b/Samples/MonoKitSample/Domain/SampleDomain.cs index bb91f9e..7bf95e3 100644 --- a/Samples/MonoKitSample/Domain/SampleDomain.cs +++ b/Samples/MonoKitSample/Domain/SampleDomain.cs @@ -17,6 +17,7 @@ // IN THE SOFTWARE. // // -------------------------------------------------------------------------------------------------------------------- +using MonoKit; namespace MonoKitSample.Domain { @@ -28,7 +29,7 @@ namespace MonoKitSample.Domain public class TestDomainContext : SqlDomainContext { - public TestDomainContext(SQLiteConnection connection, IAggregateManifestRepository manifest, IEventStoreRepository eventStore, IDomainEventBus eventBus) + public TestDomainContext(SQLiteConnection connection, IAggregateManifestRepository manifest, IEventStoreRepository eventStore, INotificationEventBus eventBus) : base(connection, manifest, eventStore, eventBus) { this.EventSerializer = new DefaultEventSerializer(); diff --git a/Samples/MonoKitSample/Domain/SnapshotSamples.cs b/Samples/MonoKitSample/Domain/SnapshotSamples.cs index 7839b06..4f1c541 100644 --- a/Samples/MonoKitSample/Domain/SnapshotSamples.cs +++ b/Samples/MonoKitSample/Domain/SnapshotSamples.cs @@ -32,7 +32,7 @@ public static class SnapshotSamples public static IDomainContext GetDomainContext() { - var domainBus = new ObservableDomainEventBus(); + var domainBus = new ObservableNotificationEventBus(); domainBus.Subscribe((x) => Console.WriteLine("domain bus event {0}", x)); var manifest = new SqlAggregateManifestRepository(SnapshotSourcedDB.Main);