Skip to content

Commit

Permalink
Just lots more tiding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Munn committed Oct 7, 2012
1 parent 2b0c0c3 commit 269b32e
Show file tree
Hide file tree
Showing 31 changed files with 237 additions and 276 deletions.
8 changes: 4 additions & 4 deletions MonoKit.Domain/DomainContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class DomainContext : IDomainContext

private readonly Dictionary<Type, Func<IDomainContext, ISnapshotRepository>> registeredSnapshotRepositories;

public DomainContext(IAggregateManifestRepository manifest, IEventStoreRepository eventStore, IDomainEventBus eventBus)
public DomainContext(IAggregateManifestRepository manifest, IEventStoreRepository eventStore, INotificationEventBus eventBus)
{
this.Manifest = manifest;
this.EventBus = eventBus;
Expand All @@ -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; }

Expand All @@ -59,7 +59,7 @@ public virtual IUnitOfWorkScope BeginUnitOfWork()
return new DomainCommandExecutor<T>(this);
}

public virtual IAggregateRepository<T> GetAggregateRepository<T>(IDomainEventBus bus) where T : IAggregateRoot, new()
public virtual IAggregateRepository<T> GetAggregateRepository<T>(INotificationEventBus bus) where T : IAggregateRoot, new()
{
if (typeof(T).GetInterfaces().Contains(typeof(IEventSourced)))
{
Expand All @@ -76,7 +76,7 @@ public virtual IUnitOfWorkScope BeginUnitOfWork()
return repo;
}

public IList<IReadModelBuilder> GetReadModelBuilders<T>(IDomainEventBus bus) where T : IAggregateRoot, new()
public IList<IReadModelBuilder> GetReadModelBuilders<T>(INotificationEventBus bus) where T : IAggregateRoot, new()
{
var result = new List<IReadModelBuilder>();

Expand Down
33 changes: 0 additions & 33 deletions MonoKit.Domain/DomainEvent_T.cs

This file was deleted.

8 changes: 4 additions & 4 deletions MonoKit.Domain/EventExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions MonoKit.Domain/EventSourcedAggregateRepository_T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion MonoKit.Domain/IAggregateEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
6 changes: 3 additions & 3 deletions MonoKit.Domain/IDomainContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public interface IDomainContext
{
IEventStoreRepository EventStore { get; }

IDomainEventBus EventBus { get; }
INotificationEventBus EventBus { get; }

IEventSerializer EventSerializer { get; }

IUnitOfWorkScope BeginUnitOfWork();

ICommandExecutor<T> NewCommandExecutor<T>() where T : class, IAggregateRoot, new();

IAggregateRepository<T> GetAggregateRepository<T>(IDomainEventBus bus) where T : IAggregateRoot, new();
IAggregateRepository<T> GetAggregateRepository<T>(INotificationEventBus bus) where T : IAggregateRoot, new();

IList<IReadModelBuilder> GetReadModelBuilders<T>(IDomainEventBus bus) where T : IAggregateRoot, new();
IList<IReadModelBuilder> GetReadModelBuilders<T>(INotificationEventBus bus) where T : IAggregateRoot, new();
}
}

2 changes: 1 addition & 1 deletion MonoKit.Domain/IReadModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ namespace MonoKit.Domain

public interface IReadModelBuilder
{
IEnumerable<IDataModelChange> Handle(IDomainEvent evt);
IEnumerable<IDataChangeEvent> Handle(INotificationEvent evt);
}
}
7 changes: 2 additions & 5 deletions MonoKit.Domain/MonoKit.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
<Compile Include="DefaultScope.cs" />
<Compile Include="DomainCommandExecutor_T.cs" />
<Compile Include="DomainContext.cs" />
<Compile Include="DomainEvent.cs" />
<Compile Include="DomainEvent_T.cs" />
<Compile Include="EventExtensions.cs" />
<Compile Include="EventSourcedAggregateRepository_T.cs" />
<Compile Include="IAggregateCommand.cs" />
Expand All @@ -65,8 +63,6 @@
<Compile Include="IAggregateRoot.cs" />
<Compile Include="ICommandExecutor_T.cs" />
<Compile Include="IDomainContext.cs" />
<Compile Include="IDomainEvent.cs" />
<Compile Include="IDomainEventBus.cs" />
<Compile Include="IEventSerializer.cs" />
<Compile Include="IEventSourced.cs" />
<Compile Include="IEventStoreRepository.cs" />
Expand All @@ -77,10 +73,11 @@
<Compile Include="ISnapshot.cs" />
<Compile Include="ISnapshotRepository.cs" />
<Compile Include="ISnapshotSupport.cs" />
<Compile Include="ObservableDomainEventBus.cs" />
<Compile Include="ReadModelBuilder.cs" />
<Compile Include="ReadModelBuildingEventBus_T.cs" />
<Compile Include="SnapshotAggregateRepository_T.cs" />
<Compile Include="UnitOfWorkEventBus.cs" />
<Compile Include="ObservableNotificationEventBus.cs" />
<Compile Include="NotificationEventBusExtensions.cs" />
</ItemGroup>
</Project>
80 changes: 80 additions & 0 deletions MonoKit.Domain/NotificationEventBusExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NotificationEventBusExtensions.cs" company="sgmunn">
// (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.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace MonoKit.Domain
{
using System;
using MonoKit.Reactive.Subjects;
using MonoKit.Data;
using MonoKit.Reactive.Linq;

public static class NotificationEventBusExtensions
{
/// <summary>
/// Returns IDataModelEvents that are for the specified identity type. These could be events or read model changes
/// </summary>
// public static IObservable<IEvent> ForIdentity<T>(this IObservable<IDomainEvent> source)
// {
// //return source.Where (x => x != null && typeof(T).IsAssignableFrom(x.Identity.GetType()));
// return source.Where(x => x.DataModelType is T);
// }
//
// /// <summary>
// /// Returns data model changes for the given identity, events or read models
// /// </summary>
// public static IObservable<IDataModelChange> DataModelChangesForIdentity<T>(this IObservable<IDataModelEvent> source) where T : IUniqueIdentity
// {
// return source.ForIdentity<T>()
// .OfType<IDataModelChange>();
// }
//
// /// <summary>
// /// Returns events for the given identity type
// /// </summary>
// public static IObservable<IAggregateEvent> EventsForIdentity<T>(this IObservable<IDataModelEvent> source) where T : IUniqueIdentity
// {
// return source.ForIdentity<T>()
// .OfType<IAggregateEvent>();
// }

/// <summary>
/// Returns data model changes for the specified read model type, excluding deleted read models
/// </summary>
public static IObservable<T> DataModelChangesForType<T>(this IObservable<INotificationEvent> source)
{
return source.Select(x => x.Event)
.OfType<IDataChangeEvent>()
//.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);
}

/// <summary>
/// Returns delete notifications for read models of the specified identity type
/// </summary>
// public static IObservable<IUniqueIdentity> DataModelDeletionsForIdentity<T>(this IObservable<IDataModelEvent> source) where T : IUniqueIdentity
// {
// return source.ForIdentity<T>()
// .OfType<IDataModelChange>()
// .Where(x => x.Deleted)
// .Select(x => x.Identity);
// }
}
}
98 changes: 0 additions & 98 deletions MonoKit.Domain/ObservableDomainEventBus.cs

This file was deleted.

46 changes: 46 additions & 0 deletions MonoKit.Domain/ObservableNotificationEventBus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ObservableNotificationEventBus.cs" company="sgmunn">
// (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.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace MonoKit.Domain
{
using System;
using MonoKit.Reactive.Subjects;

public sealed class ObservableNotificationEventBus : INotificationEventBus
{
private readonly Subject<INotificationEvent> eventPublisher;

public ObservableNotificationEventBus()
{
this.eventPublisher = new Subject<INotificationEvent>();
}

public void Publish(INotificationEvent evt)
{
this.eventPublisher.OnNext(evt);
}

public IDisposable Subscribe(IObserver<INotificationEvent> observer)
{
return this.eventPublisher.Subscribe(observer);
}
}
}

Loading

0 comments on commit 269b32e

Please sign in to comment.