This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1597b9b
commit 65ce4b5
Showing
25 changed files
with
383 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,4 +258,5 @@ paket-files/ | |
|
||
# Python Tools for Visual Studio (PTVS) | ||
__pycache__/ | ||
*.pyc | ||
*.pyc | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
samples/Shriek.Sample.EventStorage.EFCore/Handlers/DomainNotificationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Shriek.Notifications; | ||
|
||
namespace Shriek.Sample.EventStorage.EFCore.Notifications | ||
{ | ||
public class DomainNotificationHandler : IDomainNotificationHandler<DomainNotification> | ||
{ | ||
private List<DomainNotification> _notifications; | ||
|
||
public DomainNotificationHandler() | ||
{ | ||
_notifications = new List<DomainNotification>(); | ||
} | ||
|
||
public void Handle(DomainNotification message) | ||
{ | ||
Console.WriteLine("exception:" + message.Key + ":" + message.Value); | ||
_notifications.Add(message); | ||
} | ||
|
||
public List<DomainNotification> Notifications | ||
{ | ||
get => _notifications; | ||
} | ||
|
||
public bool NotEmpty | ||
{ | ||
get => Notifications.Any(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_notifications = new List<DomainNotification>(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
samples/Shriek.Sample.EventStorage.EFCore/Handlers/TodoCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Shriek.Storage; | ||
using Shriek.Samples.Aggregates; | ||
using Shriek.Samples.Commands; | ||
using Shriek.Commands; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Shriek.Sample.EventStorage.EFCore.Handlers | ||
{ | ||
public class TodoCommandHandler : ICommandHandler<CreateTodoCommand>, | ||
ICommandHandler<ChangeTodoCommand> | ||
{ | ||
public TodoCommandHandler() | ||
{ | ||
} | ||
|
||
public void Execute(ICommandContext context, CreateTodoCommand command) | ||
{ | ||
var root = context.GetAggregateRoot(command.AggregateId, () => TodoAggregateRoot.Register(command)); | ||
} | ||
|
||
public void Execute(ICommandContext context, ChangeTodoCommand command) | ||
{ | ||
var root = context.GetAggregateRoot<TodoAggregateRoot>(command.AggregateId); | ||
if (root == null) return; | ||
root.Change(command); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
samples/Shriek.Sample.EventStorage.EFCore/Handlers/TodoEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using Shriek.Samples.Events; | ||
using Shriek.Events; | ||
|
||
namespace Shriek.Sample.EventStorage.EFCore.Handlers | ||
{ | ||
public class TodoEventHandler : IEventHandler<TodoCreatedEvent>, IEventHandler<TodoChangedEvent> | ||
{ | ||
public void Handle(TodoCreatedEvent e) | ||
{ | ||
System.Console.WriteLine($"here is {nameof(TodoCreatedEvent)}:" + e.Name); | ||
Thread.Sleep(5000); | ||
System.Console.WriteLine($"{e.Name} finished!"); | ||
} | ||
|
||
public void Handle(TodoChangedEvent e) | ||
{ | ||
System.Console.WriteLine($"here is {nameof(TodoCreatedEvent)}:" + e.Name); | ||
Thread.Sleep(5000); | ||
System.Console.WriteLine($"{e.Name} finished!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Shriek.Commands; | ||
using Shriek.Samples.Commands; | ||
using Shriek.EventStorage.EFCore; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Shriek.Sample.EventStorage.EFCore | ||
{ | ||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
var services = new ServiceCollection(); | ||
var connectionStringBuilder = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder { DataSource = "shriek.sample.db" }; | ||
var connectionString = connectionStringBuilder.ToString(); | ||
|
||
services.AddShriek(); | ||
services.AddEFCoreEventStorage(options => | ||
options.UseSqlite(connectionString)); | ||
|
||
var container = services.BuildServiceProvider(); | ||
|
||
var bus = container.GetService<ICommandBus>(); | ||
|
||
var id = Guid.NewGuid(); | ||
|
||
bus.Send(new CreateTodoCommand(id) | ||
{ | ||
Name = "get up", | ||
Desception = "good day", | ||
FinishTime = DateTime.Now.AddDays(1) | ||
}); | ||
|
||
Console.WriteLine($"{nameof(CreateTodoCommand)} sended!"); | ||
|
||
bus.Send(new ChangeTodoCommand(id) | ||
{ | ||
Name = "eat breakfast", | ||
Desception = "yummy!", | ||
FinishTime = DateTime.Now.AddDays(1) | ||
}); | ||
|
||
Console.WriteLine($"{nameof(ChangeTodoCommand)} sended!"); | ||
|
||
bus.Send(new ChangeTodoCommand(id) | ||
{ | ||
Name = "go to work", | ||
Desception = "fighting!", | ||
FinishTime = DateTime.Now.AddDays(1) | ||
}); | ||
Console.WriteLine($"{nameof(ChangeTodoCommand)} sended!"); | ||
|
||
bus.Send(new ChangeTodoCommand(id) | ||
{ | ||
Name = "call boss", | ||
Desception = "haha!", | ||
FinishTime = DateTime.Now.AddDays(1) | ||
}); | ||
Console.WriteLine($"{nameof(ChangeTodoCommand)} sended!"); | ||
|
||
bus.Send(new ChangeTodoCommand(id) | ||
{ | ||
Name = "coding", | ||
Desception = "great!", | ||
FinishTime = DateTime.Now.AddDays(1) | ||
}); | ||
Console.WriteLine($"{nameof(ChangeTodoCommand)} sended!"); | ||
|
||
bus.Send(new ChangeTodoCommand(id) | ||
{ | ||
Name = "drive car", | ||
Desception = "be careful!", | ||
FinishTime = DateTime.Now.AddDays(-1) | ||
}); | ||
Console.WriteLine($"{nameof(ChangeTodoCommand)} sended!"); | ||
|
||
Console.ReadKey(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/Shriek.Sample.EventStorage.EFCore/Shriek.Sample.EventStorage.EFCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Shriek.EventStorage.EFCore\Shriek.EventStorage.EFCore.csproj" /> | ||
<ProjectReference Include="..\..\src\Shriek\Shriek.csproj" /> | ||
<ProjectReference Include="..\Shriek.Samples\Shriek.Samples.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
src/Shriek.EventStorage.EFCore/EventStorageEFCoreExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Shriek.EventSourcing; | ||
using Shriek.Storage; | ||
using Shriek.EventSourcing.Sql.EFCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Shriek.EventStorage.EFCore | ||
{ | ||
public static class EventStorageEFCoreExtensions | ||
{ | ||
public static void AddEFCoreEventStorage(this IServiceCollection services, Action<DbContextOptionsBuilder> optionsAction = null) | ||
{ | ||
services.AddDbContext<EventStorageSQLContext>(optionsAction); | ||
services.AddScoped<IEventStorageRepository, EventStorageSQLRepository>(); | ||
services.AddScoped<IEventStorage, SqlEventStorage>(); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Shriek.Events | ||
{ | ||
public class StoredEvent : Event | ||
{ | ||
public StoredEvent(Guid aggregateId, string data, string user) | ||
{ | ||
AggregateId = aggregateId; | ||
Data = data; | ||
User = user; | ||
} | ||
|
||
// EF Constructor | ||
protected StoredEvent() { } | ||
|
||
public string Data { get; private set; } | ||
|
||
public string User { get; private set; } | ||
} | ||
} |
6 changes: 1 addition & 5 deletions
6
src/Shriek.EventStorage.EF/StoredEventMap.cs → ...iek.EventStorage.EFCore/StoredEventMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.