Skip to content

Commit

Permalink
Add Private constructor in Result
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadKarimi committed Jan 13, 2024
1 parent b826b41 commit eb05f8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/SwiftLink.Presentation/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public abstract class BaseController : Controller
{
private ISender? _mediatR;
protected ISender MediatR => _mediatR ??= HttpContext.RequestServices.GetRequiredService<ISender>();

}
17 changes: 12 additions & 5 deletions src/SwiftLink.Shared/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ public class Result<T> : 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<T> Success(T result)
=> new(result, Error.None, true);
=> new(result);

public new static Result<T> Failure(Error error)
=> new(default!, error, false);
=> new(error);
}

0 comments on commit eb05f8b

Please sign in to comment.