diff --git a/API/Content/Services/IResult.cs b/API/Content/Services/IResult.cs deleted file mode 100644 index 0f4a0680..00000000 --- a/API/Content/Services/IResult.cs +++ /dev/null @@ -1,15 +0,0 @@ -using GenHTTP.Api.Protocol; - -namespace GenHTTP.Api.Content.Services -{ - - public interface IResult - { - - object? Payload { get; } - - void Apply(IResponseBuilder builder); - - } - -} diff --git a/API/Protocol/IResponseModification.cs b/API/Protocol/IResponseModification.cs index 9f7e73cf..8d0a6c7d 100644 --- a/API/Protocol/IResponseModification.cs +++ b/API/Protocol/IResponseModification.cs @@ -3,7 +3,12 @@ namespace GenHTTP.Api.Protocol { - public interface IResponseModification + /// + /// The protocol allowing to manipulate the response sent by + /// the server. + /// + /// The type of builder used as a return value + public interface IResponseModification { /// diff --git a/Modules/Reflection/IResultWrapper.cs b/Modules/Reflection/IResultWrapper.cs new file mode 100644 index 00000000..d8d646b9 --- /dev/null +++ b/Modules/Reflection/IResultWrapper.cs @@ -0,0 +1,27 @@ +using GenHTTP.Api.Protocol; + +namespace GenHTTP.Modules.Reflection +{ + + /// + /// Allows the framework to unwrap + /// instances. + /// + internal interface IResultWrapper + { + + /// + /// The actual result to be returned. + /// + object? Payload { get; } + + /// + /// Performs the configured modifications to the response + /// on the given builder. + /// + /// The response builder to manipulate + void Apply(IResponseBuilder builder); + + } + +} diff --git a/Modules/Reflection/ResponseProvider.cs b/Modules/Reflection/ResponseProvider.cs index 74cb87e3..c5e5ce41 100644 --- a/Modules/Reflection/ResponseProvider.cs +++ b/Modules/Reflection/ResponseProvider.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using GenHTTP.Api.Content; -using GenHTTP.Api.Content.Services; using GenHTTP.Api.Protocol; using GenHTTP.Modules.Basics; @@ -51,7 +50,7 @@ public ResponseProvider(SerializationRegistry? serialization) var type = result.GetType(); // unwrap the result if applicable - if (type is IResult wrapped) + if (type is IResultWrapper wrapped) { return await GetResponseAsync(request, handler, wrapped.Payload, (b) => wrapped.Apply(b)).ConfigureAwait(false); } diff --git a/API/Content/Services/Result.cs b/Modules/Reflection/Result.cs similarity index 69% rename from API/Content/Services/Result.cs rename to Modules/Reflection/Result.cs index 4e48a013..960aec73 100644 --- a/API/Content/Services/Result.cs +++ b/Modules/Reflection/Result.cs @@ -3,10 +3,21 @@ using GenHTTP.Api.Protocol; -namespace GenHTTP.Api.Content.Services +namespace GenHTTP.Modules.Reflection { - public class Result : IResult, IResponseModification> + /// + /// A result of a service invocation that wraps a given payload and + /// still allows to modify the response generated by the server. + /// + /// The type of payload wrapped by this result + /// + /// Useful to change response properties (such as the status code or headers) + /// while still keeping the content in place. Note that returning a result + /// will not change the serialized outcome of the service method, it will be + /// the same as it would be when you would just return the payload itself. + /// + public class Result : IResultWrapper, IResponseModification> { private FlexibleResponseStatus? _Status; @@ -24,14 +35,21 @@ public class Result : IResult, IResponseModification> #region Get-/Setters + /// + /// The actual data to be returned to the client. + /// public T? Payload { get; } - object? IResult.Payload => Payload; + object? IResultWrapper.Payload => Payload; #endregion #region Initialization + /// + /// Creates a new result with the given payload. + /// + /// The payload to be returned to the client public Result(T? payload) { Payload = payload; @@ -41,18 +59,21 @@ public Result(T? payload) #region Functionality + /// public Result Status(ResponseStatus status) { _Status = new(status); return this; } + /// public Result Status(int status, string reason) { _Status = new FlexibleResponseStatus(status, reason); return this; } + /// public Result Header(string key, string value) { if (_Headers == null) @@ -65,18 +86,21 @@ public Result Header(string key, string value) return this; } + /// public Result Expires(DateTime expiryDate) { _Expires = expiryDate; return this; } + /// public Result Modified(DateTime modificationDate) { _Modified = modificationDate; return this; } + /// public Result Cookie(Cookie cookie) { if (_Cookies == null) @@ -89,19 +113,21 @@ public Result Cookie(Cookie cookie) return this; } + /// public Result Type(FlexibleContentType contentType) { _ContentType = contentType; return this; } + /// public Result Encoding(string encoding) { _Encoding = encoding; return this; } - public void Apply(IResponseBuilder builder) + void IResultWrapper.Apply(IResponseBuilder builder) { if (_Status != null) {