diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Events.cs b/Events.cs new file mode 100644 index 0000000..018c062 --- /dev/null +++ b/Events.cs @@ -0,0 +1,24 @@ +using System; + +namespace EventSourcing.Demo +{ + public interface IEvent + { + string EventType { get; } + } + + public record ProductShipped(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductShipped"; + } + + public record ProductReceived(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductReceived"; + } + + public record InventoryAdjusted(string Sku, int Quantity, string Reason, DateTime DateTime) : IEvent + { + public string EventType { get; } = "InventoryAdjusted"; + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Events.cs b/Events.cs new file mode 100644 index 0000000..018c062 --- /dev/null +++ b/Events.cs @@ -0,0 +1,24 @@ +using System; + +namespace EventSourcing.Demo +{ + public interface IEvent + { + string EventType { get; } + } + + public record ProductShipped(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductShipped"; + } + + public record ProductReceived(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductReceived"; + } + + public record InventoryAdjusted(string Sku, int Quantity, string Reason, DateTime DateTime) : IEvent + { + public string EventType { get; } = "InventoryAdjusted"; + } +} \ No newline at end of file diff --git a/InvalidDomainException.cs b/InvalidDomainException.cs new file mode 100644 index 0000000..5968c60 --- /dev/null +++ b/InvalidDomainException.cs @@ -0,0 +1,12 @@ +using System; + +namespace SlimDomainModel +{ + public class InvalidDomainException : Exception + { + public InvalidDomainException(string message) : base(message) + { + + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Events.cs b/Events.cs new file mode 100644 index 0000000..018c062 --- /dev/null +++ b/Events.cs @@ -0,0 +1,24 @@ +using System; + +namespace EventSourcing.Demo +{ + public interface IEvent + { + string EventType { get; } + } + + public record ProductShipped(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductShipped"; + } + + public record ProductReceived(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductReceived"; + } + + public record InventoryAdjusted(string Sku, int Quantity, string Reason, DateTime DateTime) : IEvent + { + public string EventType { get; } = "InventoryAdjusted"; + } +} \ No newline at end of file diff --git a/InvalidDomainException.cs b/InvalidDomainException.cs new file mode 100644 index 0000000..5968c60 --- /dev/null +++ b/InvalidDomainException.cs @@ -0,0 +1,12 @@ +using System; + +namespace SlimDomainModel +{ + public class InvalidDomainException : Exception + { + public InvalidDomainException(string message) : base(message) + { + + } + } +} \ No newline at end of file diff --git a/SlimDomainModel.csproj b/SlimDomainModel.csproj new file mode 100644 index 0000000..f8a708f --- /dev/null +++ b/SlimDomainModel.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Events.cs b/Events.cs new file mode 100644 index 0000000..018c062 --- /dev/null +++ b/Events.cs @@ -0,0 +1,24 @@ +using System; + +namespace EventSourcing.Demo +{ + public interface IEvent + { + string EventType { get; } + } + + public record ProductShipped(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductShipped"; + } + + public record ProductReceived(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductReceived"; + } + + public record InventoryAdjusted(string Sku, int Quantity, string Reason, DateTime DateTime) : IEvent + { + public string EventType { get; } = "InventoryAdjusted"; + } +} \ No newline at end of file diff --git a/InvalidDomainException.cs b/InvalidDomainException.cs new file mode 100644 index 0000000..5968c60 --- /dev/null +++ b/InvalidDomainException.cs @@ -0,0 +1,12 @@ +using System; + +namespace SlimDomainModel +{ + public class InvalidDomainException : Exception + { + public InvalidDomainException(string message) : base(message) + { + + } + } +} \ No newline at end of file diff --git a/SlimDomainModel.csproj b/SlimDomainModel.csproj new file mode 100644 index 0000000..f8a708f --- /dev/null +++ b/SlimDomainModel.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/WarehouseProduct.cs b/WarehouseProduct.cs new file mode 100644 index 0000000..0b1a95c --- /dev/null +++ b/WarehouseProduct.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using SlimDomainModel; + +namespace EventSourcing.Demo.Slim +{ + public class WarehouseProductState + { + public int QuantityOnHand { get; set; } + } + + public class WarehouseProduct + { + private readonly string _sku; + private readonly List _uncommittedEvents = new(); + private readonly WarehouseProductState _warehouseProductState = new(); + + public WarehouseProduct(string sku) + { + _sku = sku; + } + + public void ShipProduct(int quantity) + { + if (quantity > _warehouseProductState.QuantityOnHand) + { + throw new InvalidDomainException("Ah... we don't have enough product to ship?"); + } + + AddEvent(new ProductShipped(_sku, quantity, DateTime.UtcNow)); + } + + public void ReceiveProduct(int quantity) + { + AddEvent(new ProductReceived(_sku, quantity, DateTime.UtcNow)); + } + + public void AdjustInventory(int quantity, string reason) + { + if (_warehouseProductState.QuantityOnHand + quantity < 0) + { + throw new InvalidDomainException("Cannot adjust to a negative quantity on hand."); + } + + AddEvent(new InventoryAdjusted(_sku, quantity, reason, DateTime.UtcNow)); + } + + private void Apply(ProductShipped evnt) + { + _warehouseProductState.QuantityOnHand -= evnt.Quantity; + } + + private void Apply(ProductReceived evnt) + { + _warehouseProductState.QuantityOnHand += evnt.Quantity; + } + + private void Apply(InventoryAdjusted evnt) + { + _warehouseProductState.QuantityOnHand += evnt.Quantity; + } + + public void ApplyEvent(IEvent evnt) + { + switch (evnt) + { + case ProductShipped shipProduct: + Apply(shipProduct); + break; + case ProductReceived receiveProduct: + Apply(receiveProduct); + break; + case InventoryAdjusted inventoryAdjusted: + Apply(inventoryAdjusted); + break; + default: + throw new InvalidOperationException("Unsupported Event."); + } + } + + private void AddEvent(IEvent evnt) + { + ApplyEvent(evnt); + _uncommittedEvents.Add(evnt); + } + + public IReadOnlyCollection Events() => _uncommittedEvents.AsReadOnly(); + } + + +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Events.cs b/Events.cs new file mode 100644 index 0000000..018c062 --- /dev/null +++ b/Events.cs @@ -0,0 +1,24 @@ +using System; + +namespace EventSourcing.Demo +{ + public interface IEvent + { + string EventType { get; } + } + + public record ProductShipped(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductShipped"; + } + + public record ProductReceived(string Sku, int Quantity, DateTime DateTime) : IEvent + { + public string EventType { get; } = "ProductReceived"; + } + + public record InventoryAdjusted(string Sku, int Quantity, string Reason, DateTime DateTime) : IEvent + { + public string EventType { get; } = "InventoryAdjusted"; + } +} \ No newline at end of file diff --git a/InvalidDomainException.cs b/InvalidDomainException.cs new file mode 100644 index 0000000..5968c60 --- /dev/null +++ b/InvalidDomainException.cs @@ -0,0 +1,12 @@ +using System; + +namespace SlimDomainModel +{ + public class InvalidDomainException : Exception + { + public InvalidDomainException(string message) : base(message) + { + + } + } +} \ No newline at end of file diff --git a/SlimDomainModel.csproj b/SlimDomainModel.csproj new file mode 100644 index 0000000..f8a708f --- /dev/null +++ b/SlimDomainModel.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/WarehouseProduct.cs b/WarehouseProduct.cs new file mode 100644 index 0000000..0b1a95c --- /dev/null +++ b/WarehouseProduct.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using SlimDomainModel; + +namespace EventSourcing.Demo.Slim +{ + public class WarehouseProductState + { + public int QuantityOnHand { get; set; } + } + + public class WarehouseProduct + { + private readonly string _sku; + private readonly List _uncommittedEvents = new(); + private readonly WarehouseProductState _warehouseProductState = new(); + + public WarehouseProduct(string sku) + { + _sku = sku; + } + + public void ShipProduct(int quantity) + { + if (quantity > _warehouseProductState.QuantityOnHand) + { + throw new InvalidDomainException("Ah... we don't have enough product to ship?"); + } + + AddEvent(new ProductShipped(_sku, quantity, DateTime.UtcNow)); + } + + public void ReceiveProduct(int quantity) + { + AddEvent(new ProductReceived(_sku, quantity, DateTime.UtcNow)); + } + + public void AdjustInventory(int quantity, string reason) + { + if (_warehouseProductState.QuantityOnHand + quantity < 0) + { + throw new InvalidDomainException("Cannot adjust to a negative quantity on hand."); + } + + AddEvent(new InventoryAdjusted(_sku, quantity, reason, DateTime.UtcNow)); + } + + private void Apply(ProductShipped evnt) + { + _warehouseProductState.QuantityOnHand -= evnt.Quantity; + } + + private void Apply(ProductReceived evnt) + { + _warehouseProductState.QuantityOnHand += evnt.Quantity; + } + + private void Apply(InventoryAdjusted evnt) + { + _warehouseProductState.QuantityOnHand += evnt.Quantity; + } + + public void ApplyEvent(IEvent evnt) + { + switch (evnt) + { + case ProductShipped shipProduct: + Apply(shipProduct); + break; + case ProductReceived receiveProduct: + Apply(receiveProduct); + break; + case InventoryAdjusted inventoryAdjusted: + Apply(inventoryAdjusted); + break; + default: + throw new InvalidOperationException("Unsupported Event."); + } + } + + private void AddEvent(IEvent evnt) + { + ApplyEvent(evnt); + _uncommittedEvents.Add(evnt); + } + + public IReadOnlyCollection Events() => _uncommittedEvents.AsReadOnly(); + } + + +} \ No newline at end of file diff --git a/WarehouseProductLarge.cs b/WarehouseProductLarge.cs new file mode 100644 index 0000000..c7a1308 --- /dev/null +++ b/WarehouseProductLarge.cs @@ -0,0 +1,64 @@ +using System; +using SlimDomainModel; + +namespace EventSourcing.Demo.Large +{ + public class WarehouseProduct + { + public string Sku { get; private set; } + public string Name { get; private set; } + public string Description { get; private set; } + public decimal Price { get; private set; } + public int QuantityOnHand { get; private set; } + + public void SetName(string name) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentException("Name cannot be blank."); + } + + Name = name; + } + + public void SetDescription(string description) + { + Description = description; + } + + public void SetPrice(decimal price) + { + if (price < 0) + { + throw new ArgumentException("Price must be greater than 0."); + } + + Price = price; + } + + public void ShipProduct(int quantity) + { + if (quantity > QuantityOnHand) + { + throw new InvalidDomainException("Ah... we don't have enough product to ship!"); + } + + QuantityOnHand -= quantity; + } + + public void ReceiveProduct(int quantity) + { + QuantityOnHand += quantity; + } + + public void AdjustInventory(int quantity) + { + if (QuantityOnHand + quantity < 0) + { + throw new InvalidDomainException("Cannot adjust to a negative quantity on hand."); + } + + QuantityOnHand += quantity; + } + } +} \ No newline at end of file