From eb05f8b104219e5dcb13d88a721a1a3e1d6ad2ce Mon Sep 17 00:00:00 2001 From: mohammadKarimi Date: Sat, 13 Jan 2024 14:13:15 +0330 Subject: [PATCH] Add Private constructor in Result --- .../Controllers/BaseController.cs | 1 + src/SwiftLink.Shared/Result.cs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/SwiftLink.Presentation/Controllers/BaseController.cs b/src/SwiftLink.Presentation/Controllers/BaseController.cs index 4eb504e..91c244e 100644 --- a/src/SwiftLink.Presentation/Controllers/BaseController.cs +++ b/src/SwiftLink.Presentation/Controllers/BaseController.cs @@ -9,4 +9,5 @@ public abstract class BaseController : Controller { private ISender? _mediatR; protected ISender MediatR => _mediatR ??= HttpContext.RequestServices.GetRequiredService(); + } \ No newline at end of file diff --git a/src/SwiftLink.Shared/Result.cs b/src/SwiftLink.Shared/Result.cs index 51b23cb..742ef0d 100644 --- a/src/SwiftLink.Shared/Result.cs +++ b/src/SwiftLink.Shared/Result.cs @@ -38,16 +38,23 @@ public class Result : Result { public T Data { get; } - private Result(T data, Error error, bool success) + private Result(Error error) { - Data = data; + Data = default!; Error = error; - IsSuccess = success; + IsSuccess = false; + } + + private Result(T data) + { + Data = data; + Error = Error.None; + IsSuccess = true; } public static Result Success(T result) - => new(result, Error.None, true); + => new(result); public new static Result Failure(Error error) - => new(default!, error, false); + => new(error); }