You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple library to implement the Result pattern for returning from services. It also provides a mechanism for translating the Result object to an [ActionResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.actionresult?view=aspnetcore-7.0) or [IResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iresult?view=aspnetcore-7.0).
15
15
16
16
> This library was inspired by [Ardalis.Result](https://github.com/ardalis/Result).
17
17
18
-
See the [API documentation](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.html) for more information on this project.
18
+
See the [API documentation](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.html) for more information on this project.
19
19
20
20
## Index
21
21
@@ -160,7 +160,7 @@ With any of these types you can handle errors and at the same time generate erro
160
160
161
161
This approach provides a new way to generate an error using return statements without the need to throw exceptions.
162
162
163
-
See the [API documentation](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.html) for more information on these types.
163
+
See the [API documentation](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.html) for more information on these types.
164
164
165
165
### Using the `Result` type
166
166
@@ -353,9 +353,9 @@ public class UserService
353
353
354
354
### Integration with ASP.NET Core
355
355
356
-
You can convert the Result object to a [Microsoft.AspNetCore.Mvc.ActionResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.actionresult-1?view=aspnetcore-7.0) using the [ToActionResult](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.ResultExtensions.ToActionResult.html) extension method.
356
+
You can convert the Result object to a [Microsoft.AspNetCore.Mvc.ActionResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.actionresult-1?view=aspnetcore-7.0) using the [ToActionResult](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.ResultExtensions.ToActionResult.html) extension method.
357
357
358
-
You need to install the [SimpleResults.AspNetCore](https://www.nuget.org/packages/SimpleResults.AspNetCore) package to have access to the extension method. See the [ResultExtensions](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.ResultExtensions.html#methods) class to find all extension methods.
358
+
You need to install the [SimpleResults.AspNetCore](https://www.nuget.org/packages/SimpleResults.AspNetCore) package to have access to the extension method. See the [ResultExtensions](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.ResultExtensions.html#methods) class to find all extension methods.
359
359
360
360
**Example:**
361
361
```cs
@@ -394,11 +394,11 @@ public class UserController
394
394
=>_userService.GetAll().ToActionResult();
395
395
}
396
396
```
397
-
See the [API documentation](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.ResultExtensions.html#methods) for a list of available extension methods.
397
+
See the [API documentation](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.ResultExtensions.html#methods) for a list of available extension methods.
398
398
399
399
#### Using TranslateResultToActionResult as an action filter
400
400
401
-
You can also use the [TranslateResultToActionResult](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.TranslateResultToActionResultAttribute.html) filter to translate the Result object to [ActionResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.actionresult?view=aspnetcore-7.0).
401
+
You can also use the [TranslateResultToActionResult](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.TranslateResultToActionResultAttribute.html) filter to translate the Result object to [ActionResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.actionresult?view=aspnetcore-7.0).
402
402
403
403
`TranslateResultToActionResultAttribute` class will internally call the `ToActionResult` method and perform the translation.
404
404
@@ -418,11 +418,11 @@ public class UserController
418
418
```
419
419
The return value of `Get` action is a `Result<User>`. **After the action is executed**, the filter (i.e. `TranslateResultToActionResult`) will run and translate the `Result<User>` to [ActionResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.actionresult?view=aspnetcore-7.0).
420
420
421
-
[See the source code](https://github.com/MrDave1999/SimpleResults/blob/e0b4bf02c77c02862f0a95ded268ee05cbc6d033/src/AspNetCore/TranslateResultToActionResultAttribute.cs#L12), it is very simple.
421
+
[See the source code](https://github.com/DevD4v3/SimpleResults/blob/e0b4bf02c77c02862f0a95ded268ee05cbc6d033/src/AspNetCore/TranslateResultToActionResultAttribute.cs#L12), it is very simple.
422
422
423
423
#### Add action filter as global
424
424
425
-
If you do not want to use the filter on each controller, you can add it globally for all controllers (see [sample](https://github.com/MrDave1999/SimpleResults/blob/e0b4bf02c77c02862f0a95ded268ee05cbc6d033/samples/SimpleResults.Example.AspNetCore/Program.cs#L10C1-L14C4)).
425
+
If you do not want to use the filter on each controller, you can add it globally for all controllers (see [sample](https://github.com/DevD4v3/SimpleResults/blob/e0b4bf02c77c02862f0a95ded268ee05cbc6d033/samples/SimpleResults.Example.AspNetCore/Program.cs#L10C1-L14C4)).
426
426
```cs
427
427
builder.Services.AddControllers(options=>
428
428
{
@@ -436,7 +436,7 @@ This way you no longer need to add the `TranslateResultToActionResult` attribute
436
436
437
437
As of version 2.3.0, a feature has been added to convert the Result object to an implementation of [Microsoft.AspNetCore.Http.IResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iresult?view=aspnetcore-7.0).
438
438
439
-
You only need to use the extension method called [ToHttpResult](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.ResultExtensions.ToHttpResult.html). See the [ResultExtensions](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.ResultExtensions.html#methods) class to find all extension methods.
439
+
You only need to use the extension method called [ToHttpResult](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.ResultExtensions.ToHttpResult.html). See the [ResultExtensions](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.ResultExtensions.html#methods) class to find all extension methods.
440
440
441
441
**Example:**
442
442
```cs
@@ -464,7 +464,7 @@ public static class UserEndpoint
464
464
}
465
465
}
466
466
```
467
-
You can also use the [TranslateResultToHttpResult](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.TranslateResultToHttpResultFilter.html) filter to translate the Result object to an implementation of [IResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iresult?view=aspnetcore-7.0).
467
+
You can also use the [TranslateResultToHttpResult](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.TranslateResultToHttpResultFilter.html) filter to translate the Result object to an implementation of [IResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iresult?view=aspnetcore-7.0).
468
468
469
469
`TranslateResultToHttpResultFilter` class will internally call the `ToHttpResult` method and perform the translation.
470
470
@@ -487,15 +487,15 @@ public static class UserEndpoint
487
487
```
488
488
The endpoint handler returns a `Result<User>`. After the handler is executed, the filter (i.e. `TranslateResultToHttpResult`) will run and translate the `Result<User>` to an implementation of [IResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iresult?view=aspnetcore-7.0).
489
489
490
-
[See the source code](https://github.com/MrDave1999/SimpleResults/blob/25387945f57241dadad3baf52886ab59949c98fa/src/AspNetCore/TranslateResultToHttpResultFilter.cs#L26), it is very simple.
490
+
[See the source code](https://github.com/DevD4v3/SimpleResults/blob/25387945f57241dadad3baf52886ab59949c98fa/src/AspNetCore/TranslateResultToHttpResultFilter.cs#L26), it is very simple.
491
491
492
492
#### Validating with the ModelState property
493
493
494
494
[SimpleResults.AspNetCore](https://www.nuget.org/packages/SimpleResults.AspNetCore) package also adds extension methods for the [ModelStateDictionary](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.modelbinding.modelstatedictionary?view=aspnetcore-7.0) type.
495
495
496
-
See the [ModelStateDictionaryExtensions](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.SRModelStateDictionaryExtensions.html) class to find all extension methods.
496
+
See the [ModelStateDictionaryExtensions](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.SRModelStateDictionaryExtensions.html) class to find all extension methods.
497
497
498
-
The `ModelStateDictionary` type contains the validation errors that are displayed to the client. Somehow these errors must be included in an instance of type [Result](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.Result.html).
498
+
The `ModelStateDictionary` type contains the validation errors that are displayed to the client. Somehow these errors must be included in an instance of type [Result](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.Result.html).
499
499
500
500
##### Manual validation
501
501
@@ -520,7 +520,7 @@ public class OrderController : ControllerBase
520
520
}
521
521
}
522
522
```
523
-
In this example a manual validation is performed with `ModelState.IsFailed()` (an extension method), so if the model state is failed, an invalid result type is returned. What `ModelState.Invalid()` does is to convert the instance of `ModelStateDictionary` to an instance of type [Result](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.Result.html), so in the result object the validation errors will be added.
523
+
In this example a manual validation is performed with `ModelState.IsFailed()` (an extension method), so if the model state is failed, an invalid result type is returned. What `ModelState.Invalid()` does is to convert the instance of `ModelStateDictionary` to an instance of type [Result](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.Result.html), so in the result object the validation errors will be added.
524
524
525
525
After the controller action is executed, the `TranslateResultToActionResult` filter will translate the Result object to an instance of type `ActionResult`.
526
526
@@ -546,11 +546,11 @@ public class OrderController : ControllerBase
546
546
}
547
547
}
548
548
```
549
-
`ModelState.BadRequest()` has a behavior similar to `ModelState.Invalid()`, the difference is that the first one returns an instance of type [BadRequestObjectResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.badrequestobjectresult?view=aspnetcore-7.0) in which contains the instance of type [Result](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.Result.html).
549
+
`ModelState.BadRequest()` has a behavior similar to `ModelState.Invalid()`, the difference is that the first one returns an instance of type [BadRequestObjectResult](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.badrequestobjectresult?view=aspnetcore-7.0) in which contains the instance of type [Result](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.Result.html).
550
550
551
551
##### Automatic validation
552
552
553
-
You need to make a setting in the `Program.cs` to convert the instance of type `ModelStateDictionary` to an instance of type [Result](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.Result.html) when the model validation fails.
553
+
You need to make a setting in the `Program.cs` to convert the instance of type `ModelStateDictionary` to an instance of type [Result](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.Result.html) when the model validation fails.
554
554
555
555
**Example:**
556
556
```cs
@@ -620,22 +620,22 @@ public class UserService
620
620
}
621
621
}
622
622
```
623
-
See the [API documentation](https://mrdave1999.github.io/SimpleResults/api/SimpleResults.SRFluentValidationResultExtensions.html#methods) for a list of available extension methods.
623
+
See the [API documentation](https://DevD4v3.github.io/SimpleResults/api/SimpleResults.SRFluentValidationResultExtensions.html#methods) for a list of available extension methods.
624
624
625
625
## Samples
626
626
627
627
You can find a complete and functional example in these projects:
`SimpleResults` has resources that contain response messages. [See the source code](https://github.com/MrDave1999/SimpleResults/tree/23f5fdb4af10195b182ace9ff78fb4fbf4fa9768/src/Core/Resources).
638
+
`SimpleResults` has resources that contain response messages. [See the source code](https://github.com/DevD4v3/SimpleResults/tree/23f5fdb4af10195b182ace9ff78fb4fbf4fa9768/src/Core/Resources).
639
639
640
640
At the moment there are only two resources:
641
641
-`ResponseMessages.resx`. It contains messages in English.
0 commit comments