-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New [AlwaysPublishResponse] attribute usage for selective, explicit b…
…ackward compatibility with Wolverine <3 behavior
- Loading branch information
1 parent
071e8fa
commit 9680ef3
Showing
8 changed files
with
58 additions
and
13 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
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
37 changes: 37 additions & 0 deletions
37
src/Wolverine/Attributes/AlwaysPublishResponseAttribute.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 @@ | ||
using JasperFx.CodeGeneration; | ||
using JasperFx.CodeGeneration.Frames; | ||
using JasperFx.CodeGeneration.Model; | ||
using Wolverine.Runtime.Handlers; | ||
|
||
namespace Wolverine.Attributes; | ||
|
||
/// <summary> | ||
/// Decorate any handler method or class if you always want any response | ||
/// (the "T" in IMessageBus.InvokeAsync<T>()) to be *also* published as a | ||
/// message in addition to being the response object | ||
/// </summary> | ||
public class AlwaysPublishResponseAttribute : ModifyHandlerChainAttribute | ||
{ | ||
public override void Modify(HandlerChain chain, GenerationRules rules) | ||
{ | ||
chain.Middleware.Add(new AlwaysPublishResponseFrame()); | ||
} | ||
} | ||
|
||
internal class AlwaysPublishResponseFrame : SyncFrame | ||
{ | ||
private Variable _envelope; | ||
|
||
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) | ||
{ | ||
writer.WriteComment("Always publish the response as a message due to the [AlwaysPublishResponse] usage"); | ||
writer.WriteLine($"{_envelope.Usage}.{nameof(Envelope.DoNotCascadeResponse)} = false;"); | ||
Next?.GenerateCode(method, writer); | ||
} | ||
|
||
public override IEnumerable<Variable> FindVariables(IMethodVariables chain) | ||
{ | ||
_envelope = chain.FindVariable(typeof(Envelope)); | ||
yield return _envelope; | ||
} | ||
} |
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