Last active
August 29, 2015 14:01
-
-
Save philcleveland/ff3a5dc80816e32e6549 to your computer and use it in GitHub Desktop.
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
public class AreaFallowed | |
{ | |
public AreaFallowed(string gardenID, NodaTime.LocalDate date, int x, int y, int width, int length) | |
{ | |
GardenId = gardenID; | |
Date = date; | |
X = x; | |
Y = y; | |
Width = width; | |
Length = length; | |
} | |
public string GardenId { get; private set; } | |
public NodaTime.LocalDate Date { get; private set; } | |
public int X {get; private set;} | |
public int Y {get; private set;} | |
public int Width {get; private set;} | |
public int Length { get; private 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
public class AreaHarvested | |
{ | |
public AreaHarvested(string gardenID, NodaTime.LocalDate date, int x, int y, int width, int length) | |
{ | |
GardenId = gardenID; | |
Date = date; | |
X = x; | |
Y = y; | |
Width = width; | |
Length = length; | |
} | |
public string GardenId { get; private set; } | |
public NodaTime.LocalDate Date { get; private set; } | |
public int X { get; private set; } | |
public int Y { get; private set; } | |
public int Width { get; private set; } | |
public int Length { get; private 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
public class AreaSown | |
{ | |
public AreaSown(string gardenID, string seedID, NodaTime.LocalDate date, int x, int y, int width, int length) | |
{ | |
GardenId = gardenID; | |
SeedId = seedID; | |
Date = date; | |
X = x; | |
Y = y; | |
Width = width; | |
Length = length; | |
} | |
public string GardenId { get; private set; } | |
public string SeedId { get; private set; } | |
public NodaTime.LocalDate Date { get; private set; } | |
public int X { get; private set; } | |
public int Y { get; private set; } | |
public int Width { get; private set; } | |
public int Length { get; private 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
public class Bootstrap | |
{ | |
Projection<GardenState> _gardenProjection; | |
public void Bootstrap() | |
{ | |
var pb = new ProjectionBuilder<GardenState>(); | |
pb = pb.When<GardenCreated>((s, e) => { return s.Apply(e); }); | |
pb = pb.When<AreaFallowed>((s, e) => { return s.Apply(e); }); | |
pb = pb.When<AreaSown>((s, e) => { return s.Apply(e); }); | |
pb = pb.When<AreaHarvested>((s, e) => { return s.Apply(e); }); | |
_gardenProjection = pb.Build(); | |
var eventHandler1 = new SomeEventHandler(_gardenProjection); | |
} | |
} | |
public class SomeEventHandler : IHandleMsg<GardenCreated> | |
{ | |
GardenState _currentState; | |
Projection<GardenState> _projection | |
public void SomeEventHandler(Projection<GardenState> projection) | |
{ | |
_projection = projection; | |
} | |
public void Handle(GardenCreated @event) | |
{ | |
_currentState = _projection.Project(_currentState, @event); | |
} | |
} |
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
public class GardenCreated | |
{ | |
public GardenCreated(string gardenID, string name, NodaTime.LocalDate date, int width, int length) | |
{ | |
GardenId = gardenID; | |
GardenName = name; | |
Date = date; | |
Width = width; | |
Length = length; | |
} | |
public string GardenId { get; private set; } | |
public string GardenName { get; private set; } | |
public NodaTime.LocalDate Date { get; private set; } | |
public int Width { get; private set; } | |
public int Length { get; private 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
public class GardenState | |
{ | |
public GardenState() | |
{ | |
} | |
public GardenState(NodaTime.LocalDate createdOn, string name, int width, int length) | |
{ | |
GardenCreated = createdOn; | |
GardenName = name; | |
GardenWidth = width; | |
GardenLength = length; | |
} | |
public NodaTime.LocalDate GardenCreated { get; private set; } | |
public string GardenName { get; private set; } | |
public int GardenWidth { get; private set; } | |
public int GardenLength { get; private set; } | |
public GardenState Apply(GardenCreated @event) | |
{ | |
return new GardenState() | |
{ | |
GardenCreated = @event.Date, | |
GardenName = @event.GardenName, | |
GardenWidth = @event.Width, | |
GardenLength = @event.Length | |
}; | |
} | |
public GardenState Apply(AreaFallowed @event) | |
{ | |
//TODO: change the state based on evt | |
return new GardenState(); | |
} | |
public GardenState Apply(AreaSown @event) | |
{ | |
//TODO: change the state based on evt | |
return new GardenState(); | |
} | |
public GardenState Apply(AreaHarvested @event) | |
{ | |
//TODO: change the state based on evt | |
return new GardenState(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment