Skip to content

Commit

Permalink
Added EntityFrameworkCore. (#2)
Browse files Browse the repository at this point in the history
* Added EntityFrameworkCore.

* Fixed docs.
  • Loading branch information
jscarle authored Feb 29, 2024
1 parent fe90306 commit 49efd09
Show file tree
Hide file tree
Showing 15 changed files with 486 additions and 358 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
ignore:
- dependency-name: "Microsoft.EntityFrameworkCore"
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
run: dotnet pack --configuration Release --no-build --output .

- name: Push to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
6 changes: 6 additions & 0 deletions LightResults.Extensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightResults.Extensions.Exc
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{A6C9FED0-42B6-488C-8961-DE13F291434B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightResults.Extensions.EntityFrameworkCore", "src\LightResults.Extensions.EntityFrameworkCore\LightResults.Extensions.EntityFrameworkCore.csproj", "{9FEADBCA-FD94-437D-9C98-79C673A84C10}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -20,6 +22,10 @@ Global
{186EBDB5-A589-4E0C-AE40-E5141E438B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{186EBDB5-A589-4E0C-AE40-E5141E438B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{186EBDB5-A589-4E0C-AE40-E5141E438B58}.Release|Any CPU.Build.0 = Release|Any CPU
{9FEADBCA-FD94-437D-9C98-79C673A84C10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FEADBCA-FD94-437D-9C98-79C673A84C10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FEADBCA-FD94-437D-9C98-79C673A84C10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FEADBCA-FD94-437D-9C98-79C673A84C10}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{93C8BC67-7F34-4935-A671-F0B12AEDB072} = {A6C9FED0-42B6-488C-8961-DE13F291434B}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Extensions for [LightResults](https://github.com/jscarle/LightResults), an extre
## LightResults.Extensions.ExceptionHandling

Provides extension methods for exception handling using LightResults.

## LightResults.Extensions.EntityFrameworkCore

Provides a DbContext that wraps context operations using LightResults.
4 changes: 2 additions & 2 deletions docfx/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"modern"
],
"globalMetadata": {
"_appName": "LightResults",
"_appTitle": "LightResults",
"_appName": "LightResults.Extensions",
"_appTitle": "LightResultsExtensions",
"_appLogoPath": "images/Logo.png",
"_appFaviconPath": "images/Icon.png",
"_appFooter": "Developed and maintained by Jean-Sebastien Carle — <a href=\"https://jscarle.dev\">jscarle.dev</a><script async defer src=\"https://buttons.github.io/buttons.js\"></script><script async src=\"https://www.googletagmanager.com/gtag/js?id=G-ERKQEFDJYX\"></script>\r\n<script>\r\n window.dataLayer = window.dataLayer || [];\r\n function gtag(){dataLayer.push(arguments);}\r\n gtag('js', new Date());\r\n\r\n gtag('config', 'G-ERKQEFDJYX');\r\n</script>",
Expand Down
35 changes: 35 additions & 0 deletions docfx/docs/entityframeworkcore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## LightResults.Extensions.EntityFrameworkCore

Provides a DbContext that wraps context operations using LightResults.

### New method definitions

The following methods are wrapped internally with a `try { } catch { }` block and have their signatures
updated to result a `Result`. If an exception occurs, a failed result will be returned and the `Exception`
will be added to the result as metadata.

- `AddAsync()`
- `AddAsync<TEntity>()`
- `AddRangeAsync()`
- `Find()`
- `Find<TEntity>()`
- `FindAsync()`
- `FindAsync<TEntity>()`
- `SaveChanges()`
- `SaveChangesAsync()`

#### Getting the `Exception`

```csharp
var result = dbContext.SaveChangesAsync();
if (result.IsFailed)
{
var ex = (Exception)result.Error.Metadata["Exception"];
// Do something with the base exception type or...
if (ex is DbUpdateException dbUpdateException)
{
// Do something with a specific exception type
}
}
```
66 changes: 66 additions & 0 deletions docfx/docs/exceptionhandling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## LightResults.Extensions.ExceptionHandling

Provides extension methods for exception handling using LightResults.

### Try method

The `Try` method will wrap the execution of an `Action` or `Func` in a `try { } catch { }` block. If an
exception occurs, a failed result will be returned and the `Exception` will be added to the result as metadata.

#### With an `Action`

```csharp
var result = action.Try();
if (result.IsSuccess)
{
// Do something
}
```

#### With an `Action` with arguments

```csharp
var result = action.Try(42);
if (result.IsSuccess)
{
// Do something
}
```

#### With a `Func`

```csharp
var result = func.Try();
if (result.IsSuccess)
{
var value = result.Value;
// Do something
}
```

#### With a `Func` with arguments

```csharp
var result = func.Try(42);
if (result.IsSuccess)
{
var value = result.Value;
// Do something
}
```

#### Getting the `Exception`

```csharp
var result = action.Try();
if (result.IsFailed)
{
var ex = (Exception)result.Error.Metadata["Exception"];
// Do something with the base exception type or...
if (ex is ArgumentNullException argumentNullException)
{
// Do something with a specific exception type
}
}
```
205 changes: 0 additions & 205 deletions docfx/docs/getting-started.md

This file was deleted.

Loading

0 comments on commit 49efd09

Please sign in to comment.