-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from erikshafer/project_03_advanced_esdb
Project 03: Beginner++ ESDB
- Loading branch information
Showing
21 changed files
with
326 additions
and
56 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
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace StudentEnrollment02.Esdb.Events; | ||
|
||
public abstract record Event | ||
public abstract class Event | ||
{ | ||
public string Id { get; init; } = default!; | ||
public required string StudentId { get; set; } | ||
public DateTime CreatedAtUtc { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
namespace StudentEnrollment02.Esdb.Events; | ||
|
||
public record StudentCreated : Event | ||
public class StudentCreated : Event | ||
{ | ||
public required string FullName { get; init; } | ||
public required string Email { get; init; } | ||
public required DateTime DateOfBirth { get; init; } | ||
public DateTime CreatedAtUtc { get; init; } | ||
} |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
namespace StudentEnrollment02.Esdb.Events; | ||
|
||
public record StudentEnrolled : Event | ||
public class StudentEnrolled : Event | ||
{ | ||
public required string CourseName { get; init; } | ||
public DateTime EnrolledAtUtc { get; init; } | ||
} |
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,7 @@ | ||
namespace StudentEnrollment02.Esdb.Events; | ||
|
||
public class StudentUpdated : Event | ||
{ | ||
public required string FullName { get; init; } | ||
public required string Email { get; init; } | ||
} |
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,6 @@ | ||
namespace StudentEnrollment02.Esdb.Events; | ||
|
||
public class StudentWithdrew : Event | ||
{ | ||
public required string CourseName { get; init; } | ||
} |
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
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,6 @@ | ||
namespace StudentEnrollment03.Esdb.Events; | ||
|
||
public abstract record Event | ||
{ | ||
public string Id { get; init; } = default!; | ||
} |
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,35 @@ | ||
using System.Collections.Concurrent; | ||
|
||
namespace StudentEnrollment03.Esdb.Events; | ||
|
||
public class EventTypeMapper | ||
{ | ||
public static readonly EventTypeMapper Instance = new(); | ||
|
||
private readonly ConcurrentDictionary<string, Type?> _typeMap = new(); | ||
private readonly ConcurrentDictionary<Type, string> _typeNameMap = new(); | ||
|
||
public string ToName<TEventType>() => ToName(typeof(TEventType)); | ||
|
||
public string ToName(Type eventType) => _typeNameMap.GetOrAdd(eventType, _ => | ||
{ | ||
var eventTypeName = eventType.FullName!; | ||
_typeMap.TryAdd(eventTypeName, eventType); | ||
return eventTypeName; | ||
}); | ||
|
||
public Type? ToType(string eventTypeName) => _typeMap.GetOrAdd(eventTypeName, _ => | ||
{ | ||
var type = AppDomain.CurrentDomain | ||
.GetAssemblies() | ||
.SelectMany(a => a.GetTypes().Where(x => x.FullName == eventTypeName || x.Name == eventTypeName)) | ||
.FirstOrDefault(); | ||
|
||
if (type == null) | ||
return null; | ||
|
||
_typeNameMap.TryAdd(type, eventTypeName); | ||
|
||
return type; | ||
}); | ||
} |
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,9 @@ | ||
namespace StudentEnrollment03.Esdb.Events; | ||
|
||
public record StudentCreated : Event | ||
{ | ||
public required string FullName { get; init; } | ||
public required string Email { get; init; } | ||
public required DateTime DateOfBirth { get; init; } | ||
public DateTime CreatedAtUtc { get; init; } | ||
} |
2 changes: 1 addition & 1 deletion
2
...ment02.Esdb/Events/StudentEmailChanged.cs → ...ment03.Esdb/Events/StudentEmailChanged.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace StudentEnrollment03.Esdb.Events; | ||
|
||
public record StudentEnrolled : Event | ||
{ | ||
public required string CourseName { get; init; } | ||
public required string InstructorName { get; init; } | ||
public DateTime EnrolledAtUtc { get; init; } | ||
} |
4 changes: 2 additions & 2 deletions
4
...ollment02.Esdb/Events/StudentWithdrawn.cs → ...rollment03.Esdb/Events/StudentWithdrew.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
Oops, something went wrong.