Skip to content

Commit 4c98528

Browse files
committed
- Checkpoint: Refactor View Transforms
1 parent 4eb1363 commit 4c98528

File tree

8 files changed

+54
-33
lines changed

8 files changed

+54
-33
lines changed

src/SourceFlow/BaseAggregate.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace SourceFlow
77
/// <summary>
88
/// Base class for aggregate roots in the event-driven architecture.
99
/// </summary>
10-
/// <typeparam name="TAggregate"></typeparam>
11-
public abstract class BaseAggregate<TAggregate> : IAggregateRoot
12-
where TAggregate : class, IEntity
10+
/// <typeparam name="TAggregateEntity"></typeparam>
11+
public abstract class BaseAggregate<TAggregateEntity> : IAggregateRoot
12+
where TAggregateEntity : class, IEntity
1313
{
1414
/// <summary>
1515
/// The bus publisher used to publish events.
@@ -51,7 +51,7 @@ protected Task PublishAsync(IEvent @event)
5151
throw new InvalidOperationException(nameof(@event) + "requires source entity id");
5252

5353
if (@event.Entity.Type == null)
54-
@event.Entity.Type = typeof(TAggregate);
54+
@event.Entity.Type = typeof(TAggregateEntity);
5555

5656
return busPublisher.Publish(@event);
5757
}

src/SourceFlow/BaseSaga.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ protected Task PublishAsync<TEvent>(TEvent @event)
8484
if (@event == null)
8585
throw new ArgumentNullException(nameof(@event));
8686

87+
if (@event.Entity?.Id == null)
88+
throw new InvalidOperationException(nameof(@event) + "requires source entity id");
89+
90+
if (@event.Entity.Type == null)
91+
@event.Entity.Type = typeof(TAggregateEntity);
92+
8793
return busPublisher.Publish(@event);
8894
}
8995

src/SourceFlow/ClassDiagram.cd

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ClassDiagram MajorVersion="1" MinorVersion="1">
3-
<Class Name="SourceFlow.BaseAggregate&lt;TAggregate&gt;">
3+
<Class Name="SourceFlow.BaseAggregate&lt;TAggregateEntity&gt;">
44
<Position X="4" Y="3.25" Width="2" />
55
<TypeIdentifier>
66
<HashCode>AgQAAAAAAAABAAACAAAAAAAAAAAAAAAAAAAAAAAAAEA=</HashCode>
@@ -101,31 +101,31 @@
101101
<Class Name="SourceFlow.Impl.CommandBus">
102102
<Position X="4" Y="7.5" Width="2.5" />
103103
<TypeIdentifier>
104-
<HashCode>AAAAABEAAAAEAEACAAAAAAAABgCAAAAAAAAAABAAAAA=</HashCode>
104+
<HashCode>AAAAABEAAAAGAEACAAAAAAAABgCAAAAAAAAAAAAAAAA=</HashCode>
105105
<FileName>Impl\CommandBus.cs</FileName>
106106
</TypeIdentifier>
107107
<ShowAsAssociation>
108-
<Field Name="etlPublisher" />
108+
<Field Name="viewPublisher" />
109109
<Field Name="eventStore" />
110110
</ShowAsAssociation>
111111
<ShowAsCollectionAssociation>
112112
<Field Name="sagas" />
113113
</ShowAsCollectionAssociation>
114114
<Lollipop Position="0.2" />
115115
</Class>
116-
<Class Name="SourceFlow.Impl.ETLPublisher">
117-
<Position X="0.75" Y="8.75" Width="1.5" />
116+
<Class Name="SourceFlow.Impl.ViewPublisher">
117+
<Position X="0.5" Y="8.75" Width="2" />
118118
<TypeIdentifier>
119119
<HashCode>AAAAAAAAAAAAAAACAEAAAAACAAAAAAIAAAAAAAAAAAA=</HashCode>
120-
<FileName>Impl\ETLPublisher.cs</FileName>
120+
<FileName>Impl\ViewPublisher.cs</FileName>
121121
</TypeIdentifier>
122122
<ShowAsCollectionAssociation>
123123
<Field Name="transforms" />
124124
</ShowAsCollectionAssociation>
125125
<Lollipop Position="0.2" />
126126
</Class>
127127
<Class Name="SourceFlow.Impl.BusPublisher">
128-
<Position X="0.75" Y="5" Width="1.5" />
128+
<Position X="0.5" Y="5" Width="2" />
129129
<TypeIdentifier>
130130
<HashCode>AAAAAAAAAAAAAAAAAAAAEAACAAAAAAAAAAAAAAAAAAA=</HashCode>
131131
<FileName>Impl\BusPublisher.cs</FileName>
@@ -151,14 +151,14 @@
151151
</TypeIdentifier>
152152
</Class>
153153
<Interface Name="SourceFlow.IEventStore">
154-
<Position X="9.75" Y="7.75" Width="2.25" />
154+
<Position X="9.75" Y="8.25" Width="2.25" />
155155
<TypeIdentifier>
156156
<HashCode>ABAAgAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAA=</HashCode>
157157
<FileName>IEventStore.cs</FileName>
158158
</TypeIdentifier>
159159
</Interface>
160160
<Interface Name="SourceFlow.IBusPublisher">
161-
<Position X="0.75" Y="3.25" Width="1.5" />
161+
<Position X="0.5" Y="3.25" Width="2" />
162162
<TypeIdentifier>
163163
<HashCode>AAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
164164
<FileName>IBusPublisher.cs</FileName>
@@ -192,11 +192,11 @@
192192
<FileName>IAggregateFactory.cs</FileName>
193193
</TypeIdentifier>
194194
</Interface>
195-
<Interface Name="SourceFlow.IETLPublisher">
196-
<Position X="0.75" Y="7" Width="1.5" />
195+
<Interface Name="SourceFlow.IViewPublisher">
196+
<Position X="0.5" Y="7" Width="2" />
197197
<TypeIdentifier>
198198
<HashCode>AAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
199-
<FileName>IETLPublisher.cs</FileName>
199+
<FileName>IViewPublisher.cs</FileName>
200200
</TypeIdentifier>
201201
</Interface>
202202
<Interface Name="SourceFlow.IViewModelRepository">
@@ -221,14 +221,14 @@
221221
</TypeIdentifier>
222222
</Interface>
223223
<Interface Name="SourceFlow.IViewTransform&lt;TEvent&gt;">
224-
<Position X="0.75" Y="13" Width="2.5" />
224+
<Position X="0.5" Y="13" Width="2" />
225225
<TypeIdentifier>
226226
<HashCode>AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
227227
<FileName>IViewTransform.cs</FileName>
228228
</TypeIdentifier>
229229
</Interface>
230230
<Interface Name="SourceFlow.IViewModel">
231-
<Position X="9.75" Y="9.5" Width="2.25" />
231+
<Position X="9.75" Y="10.25" Width="2.25" />
232232
<TypeIdentifier>
233233
<HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
234234
<FileName>IViewModel.cs</FileName>
@@ -266,7 +266,7 @@
266266
</TypeIdentifier>
267267
</Interface>
268268
<Interface Name="SourceFlow.IViewTransform">
269-
<Position X="0.75" Y="11.25" Width="2.5" />
269+
<Position X="0.5" Y="11.25" Width="2" />
270270
<TypeIdentifier>
271271
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
272272
<FileName>IViewTransform.cs</FileName>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
namespace SourceFlow
55
{
66
/// <summary>
7-
/// Interface for publishing events to an ETL (Extract, Transform, Load) process.
7+
/// Interface for publishing events to an View Model Transforms.
88
/// </summary>
9-
internal interface IETLPublisher
9+
internal interface IViewPublisher
1010
{
1111
/// <summary>
12-
/// Publishes an event to the ETL process asynchronously.
12+
/// Publishes an event to the View ETL process asynchronously.
1313
/// </summary>
1414
/// <param name="event"></param>
1515
/// <returns></returns>

src/SourceFlow/Impl/BusPublisher.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Threading.Tasks;
23

34
namespace SourceFlow.Impl
@@ -29,6 +30,15 @@ public BusPublisher(ICommandBus commandBus)
2930
/// <returns></returns>
3031
async Task IBusPublisher.Publish<TEvent>(TEvent @event)
3132
{
33+
if (@event == null)
34+
throw new ArgumentNullException(nameof(@event));
35+
36+
if (@event.Entity?.Id == null)
37+
throw new InvalidOperationException(nameof(@event) + "requires source entity id");
38+
39+
if (@event.Entity.Type == null)
40+
throw new InvalidOperationException(nameof(@event) + "requires source entity Type");
41+
3242
await commandBus.Publish(@event);
3343
}
3444
}

src/SourceFlow/Impl/CommandBus.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,23 @@ internal class CommandBus : ICommandBus
2626
/// </summary>
2727
private readonly ICollection<ISaga> sagas;
2828

29-
private readonly IETLPublisher etlPublisher;
29+
/// <summary>
30+
/// Transform publisher used to publish events to view transforms.
31+
/// </summary>
32+
private readonly IViewPublisher viewPublisher;
3033

3134
/// <summary>
3235
/// Initializes a new instance of the <see cref="CommandBus"/> class.
3336
/// </summary>
3437
/// <param name="eventStore"></param>
35-
public CommandBus(IEventStore eventStore, IETLPublisher etlPublisher, ILogger<ICommandBus> logger)
38+
/// <param name="viewPublisher"></param>
39+
/// <param name="logger"></param>
40+
public CommandBus(IEventStore eventStore, IViewPublisher viewPublisher, ILogger<ICommandBus> logger)
3641
{
3742
this.eventStore = eventStore;
3843
this.logger = logger;
3944
sagas = new List<ISaga>();
40-
this.etlPublisher = etlPublisher;
45+
this.viewPublisher = viewPublisher;
4146
}
4247

4348
/// <summary>
@@ -53,7 +58,7 @@ async Task ICommandBus.Publish<TEvent>(TEvent @event)
5358
throw new ArgumentNullException(nameof(@event));
5459

5560
await PublishToSagas(@event);
56-
await etlPublisher.Publish(@event);
61+
await viewPublisher.Publish(@event);
5762
}
5863

5964
/// <summary>
@@ -121,7 +126,7 @@ async Task ICommandBus.ReplayEvents(int aggregateId)
121126
{
122127
@event.IsReplay = true;
123128
await PublishToSagas(@event);
124-
await etlPublisher.Publish(@event);
129+
await viewPublisher.Publish(@event);
125130
}
126131
}
127132

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
namespace SourceFlow.Impl
88
{
99
/// <summary>
10-
/// Implementation of the IETLPublisher interface for publishing events to an ETL process.
10+
/// Implementation of the IViewPublisher interface for publishing events to an View model transformations.
1111
/// </summary>
12-
internal class ETLPublisher : IETLPublisher
12+
internal class ViewPublisher : IViewPublisher
1313
{
1414
/// <summary>
1515
/// Collection of view model transforms that will be applied to the events to transform to view models upon publishing.
@@ -22,10 +22,10 @@ internal class ETLPublisher : IETLPublisher
2222
private ILogger logger;
2323

2424
/// <summary>
25-
/// Initializes a new instance of the <see cref="ETLPublisher"/> class.
25+
/// Initializes a new instance of the <see cref="ViewPublisher"/> class.
2626
/// </summary>
2727
/// <param name="eventTransforms"></param>
28-
public ETLPublisher(IEnumerable<IViewTransform> transforms, ILogger<ETLPublisher> logger)
28+
public ViewPublisher(IEnumerable<IViewTransform> transforms, ILogger<ViewPublisher> logger)
2929
{
3030
this.transforms = transforms;
3131
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

src/SourceFlow/IocExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public static void UseSourceFlow(this IServiceCollection services, Action<ISourc
4545

4646
services.AddSingleton<ICommandBus, CommandBus>(c => new CommandBus(
4747
c.GetService<IEventStore>(),
48-
c.GetService<IETLPublisher>(),
48+
c.GetService<IViewPublisher>(),
4949
c.GetService<ILogger<ICommandBus>>()));
5050

5151
services.AddSingleton<IAggregateFactory, AggregateFactory>();
5252
services.AddSingleton<IBusPublisher, BusPublisher>(c => new BusPublisher(c.GetService<ICommandBus>()));
5353
services.AddSingleton<IEventReplayer, EventReplayer>(c => new EventReplayer(c.GetService<ICommandBus>()));
5454
services.AddSingleton<IBusSubscriber, BusSubscriber>(c => new BusSubscriber(c.GetService<ICommandBus>()));
55-
services.AddSingleton<IETLPublisher, ETLPublisher>(c => new ETLPublisher(c.GetServices<IViewTransform>(), c.GetService<ILogger<ETLPublisher>>()));
55+
services.AddSingleton<IViewPublisher, ViewPublisher>(c => new ViewPublisher(c.GetServices<IViewTransform>(), c.GetService<ILogger<ViewPublisher>>()));
5656

5757
configuration(new SourceFlowConfig { Services = services });
5858

0 commit comments

Comments
 (0)