-
Notifications
You must be signed in to change notification settings - Fork 56
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
5cf1557
commit 23dd6c9
Showing
4 changed files
with
104 additions
and
35 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Source/TimeWarp.State.Rules/Policies.ActionHandlerPolicy.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,37 @@ | ||
namespace TimeWarp.State.Rules; | ||
|
||
public static partial class Policies | ||
{ | ||
public static PolicyDefinition CreateActionHandlerPolicy(params Assembly[] assemblies) | ||
{ | ||
BeNestedInStateCustomRule beNestedInState = new(); | ||
return Policy.Define("TimeWarp Action Handler Policy", "See https://timewarpengineering.github.io/timewarp-architecture/") | ||
.For(Types.InAssemblies(assemblies)) | ||
.Add | ||
( | ||
t => t | ||
.That() | ||
.Inherit(typeof(ActionHandler<>)) | ||
.And() | ||
.AreNotAbstract() | ||
.Should() | ||
.MeetCustomRule(beNestedInState), | ||
"Nest Handlers", | ||
"Action Handlers must be nested in the State they act upon." | ||
) | ||
.Add | ||
( | ||
t => t | ||
.That() | ||
.Inherit(typeof(ActionHandler<>)) | ||
.And() | ||
.AreNotAbstract() | ||
.Should() | ||
.BeSealed() | ||
.And() | ||
.BeInternal(), | ||
"internal sealed Handler", | ||
"Handler should be `internal sealed`." | ||
); | ||
} | ||
} |
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,20 @@ | ||
namespace TimeWarp.State.Rules; | ||
|
||
public static partial class Policies | ||
{ | ||
public static PolicyDefinition CreateActionSetPolicy(params Assembly[] assemblies) | ||
{ | ||
return Policy.Define("TimeWarp Action Set Policy", "See https://timewarpengineering.github.io/timewarp-architecture/") | ||
.For(Types.InAssemblies(assemblies)) | ||
.Add | ||
( | ||
t => t | ||
.That() | ||
.HaveNameEndingWith("ActionSet") | ||
.Should() | ||
.BeInternal(), | ||
"internal ActionSet", | ||
"ActionSets should be internal. They can still be registered with DI, but they are not intended to be called directly. The associated method will be exposed on the State." | ||
); | ||
} | ||
} |
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,46 @@ | ||
namespace TimeWarp.State.Rules; | ||
|
||
public static partial class Policies | ||
{ | ||
public static PolicyDefinition CreateStatePolicy(params Assembly[] assemblies) | ||
{ | ||
return Policy.Define("TimeWarp State Policy", "See https://timewarpengineering.github.io/timewarp-architecture/") | ||
.For(Types.InAssemblies(assemblies)) | ||
.Add | ||
( | ||
t => t | ||
.That() | ||
.Inherit(typeof(State<>)) | ||
.And() | ||
.AreNotAbstract() | ||
.Should() | ||
.HaveNameEndingWith("State"), | ||
"suffix State", | ||
"State filenames should be suffixed with `State`." | ||
) | ||
.Add | ||
( | ||
t => t | ||
.That() | ||
.Inherit(typeof(State<>)) | ||
.And() | ||
.AreNotAbstract() | ||
.Should() | ||
.BePublic(), | ||
"public State", | ||
"States should be public. This allows for them to be packaged in separate assemblies. And their methods can be called from other assemblies." | ||
) | ||
.Add | ||
( | ||
t => t | ||
.That() | ||
.Inherit(typeof(State<>)) | ||
.And() | ||
.AreNotAbstract() | ||
.Should() | ||
.BeSealed(), | ||
"sealed State", | ||
"States should be sealed. If they were to be extended, they should be made abstract." | ||
); | ||
} | ||
} |