-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 753cf73
Showing
116 changed files
with
3,537 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text=auto | ||
*.cs diff=csharp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: publish | ||
on: | ||
push: | ||
branches: [main] | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: DotNet Setup | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: "9.x.x" | ||
env: | ||
NUGET_PACKAGES: ${{ runner.temp }}/nuget/packages | ||
|
||
- name: DotNet Pack | ||
run: find ./source -name '*.csproj' -exec dotnet pack {} --configuration Release --output packages \; | ||
|
||
- name: DotNet NuGet Delete | ||
run: curl -s https://azuresearch-usnc.nuget.org/query?q=owner:rafaelfgx | jq -r '.data[] | "dotnet nuget delete \(.id) \(.version) --non-interactive --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}"' | xargs -I {} bash -c "{}" | ||
|
||
- name: DotNet NuGet Push | ||
run: dotnet nuget push "packages/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate --no-symbols |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
*.bat | ||
*.dll | ||
*.exe | ||
*.lib | ||
*.log | ||
*.pdb | ||
*.ps1 | ||
*.suo | ||
*.tmp | ||
*.user | ||
*.userprefs | ||
*.vspx | ||
.vs | ||
[Bb]in | ||
[Dd]ebug | ||
[Ll]og | ||
[Oo]bj | ||
[Rr]elease | ||
[Rr]eleases | ||
[Tt]est[Rr]esults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# DotNetCore | ||
|
||
![](https://github.com/rafaelfgx/DotNetCore/actions/workflows/publish.yaml/badge.svg) | ||
|
||
.NET Nuget Packages. | ||
|
||
https://www.nuget.org/profiles/rafaelfgx | ||
|
||
## Documentation | ||
|
||
[AspNetCore](https://github.com/rafaelfgx/DotNetCore/tree/main/source/AspNetCore) | ||
|
||
[Domain](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Domain) | ||
|
||
[EntityFrameworkCore](https://github.com/rafaelfgx/DotNetCore/tree/main/source/EntityFrameworkCore) | ||
|
||
[Extensions](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Extensions) | ||
|
||
[IoC](https://github.com/rafaelfgx/DotNetCore/tree/main/source/IoC) | ||
|
||
[Logging](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Logging) | ||
|
||
[Mapping](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Mapping) | ||
|
||
[Mediator](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Mediator) | ||
|
||
[MongoDB](https://github.com/rafaelfgx/DotNetCore/tree/main/source/MongoDB) | ||
|
||
[Objects](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Objects) | ||
|
||
[RabbitMQ](https://github.com/rafaelfgx/DotNetCore/tree/main/source/RabbitMQ) | ||
|
||
[Repositories](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Repositories) | ||
|
||
[Results](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Results) | ||
|
||
[Security](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Security) | ||
|
||
[Services](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Services) | ||
|
||
[Validation](https://github.com/rafaelfgx/DotNetCore/tree/main/source/Validation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace DotNetCore.AspNetCore; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] | ||
public sealed class EnumAuthorizeAttribute : AuthorizeAttribute | ||
{ | ||
public EnumAuthorizeAttribute(params object[] roles) => Roles = string.Join(",", roles.Select(role => Enum.GetName(role.GetType(), role))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AssemblyName>DotNetCore.AspNetCore</AssemblyName> | ||
<Description>DotNetCore.AspNetCore</Description> | ||
<PackageId>DotNetCore.AspNetCore</PackageId> | ||
<PackageProjectUrl>https://github.com/rafaelfgx/DotNetCore/tree/main/source/AspNetCore</PackageProjectUrl> | ||
<PackageTags>AspNetCore, Attribute, Attributes, IApplicationBuilder, ApplicationBuilder, IHostBuilder, HostBuilder, HttpRequest, IServiceCollection, ServiceCollection, Result, Results, IActionResult, ActionResult</PackageTags> | ||
<Title>DotNetCore.AspNetCore</Title> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Objects\DotNetCore.Objects.csproj" /> | ||
<ProjectReference Include="..\Results\DotNetCore.Results.csproj" /> | ||
</ItemGroup> | ||
</Project> |
20 changes: 20 additions & 0 deletions
20
source/AspNetCore/Extensions/ApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace DotNetCore.AspNetCore; | ||
|
||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static void UseCorsAllowAny(this IApplicationBuilder application) => application.UseCors("AllowAny"); | ||
|
||
public static void UseException(this IApplicationBuilder application) | ||
{ | ||
var environment = application.ApplicationServices.GetRequiredService<IWebHostEnvironment>(); | ||
|
||
if (environment.IsDevelopment()) application.UseDeveloperExceptionPage(); | ||
} | ||
|
||
public static void UseLocalization(this IApplicationBuilder application, params string[] cultures) => application.UseRequestLocalization(options => options.AddSupportedCultures(cultures).AddSupportedUICultures(cultures).SetDefaultCulture(cultures.First())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using DotNetCore.Objects; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.StaticFiles; | ||
|
||
namespace DotNetCore.AspNetCore; | ||
|
||
public static class BinaryFileExtensions | ||
{ | ||
public static IActionResult FileResult(this Task<BinaryFile> binaryFile) | ||
{ | ||
if (binaryFile is null) return new NotFoundResult(); | ||
|
||
var file = binaryFile.Result; | ||
|
||
if (file is null) return new NotFoundResult(); | ||
|
||
new FileExtensionContentTypeProvider().TryGetContentType(file.ContentType, out var contentType); | ||
|
||
return contentType is null ? new NotFoundResult() : new FileContentResult(file.Bytes, contentType) { FileDownloadName = file.Name }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using DotNetCore.Objects; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace DotNetCore.AspNetCore; | ||
|
||
public static class HttpRequestExtensions | ||
{ | ||
public static IList<BinaryFile> Files(this HttpRequest request) | ||
{ | ||
var files = new List<BinaryFile>(); | ||
|
||
foreach (var file in request.Form.Files) | ||
{ | ||
using var memoryStream = new MemoryStream(); | ||
|
||
file.CopyTo(memoryStream); | ||
|
||
files.Add(new BinaryFile(Guid.NewGuid(), file.Name, memoryStream.ToArray(), file.Length, file.ContentType)); | ||
} | ||
|
||
return files; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace DotNetCore.AspNetCore; | ||
|
||
public class JsonStringBoolConverter : JsonConverter<bool> | ||
{ | ||
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => bool.TryParse(reader.GetString(), out var result) && result; | ||
|
||
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) => writer.WriteBooleanValue(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using DotNetCore.Results; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace DotNetCore.AspNetCore; | ||
|
||
public static class ResultExtensions | ||
{ | ||
public static IActionResult ApiResult<T>(this Result<T> result) => new ObjectResult(result.HasMessage ? result.Message : result.Value) { StatusCode = (int)result.Status }; | ||
|
||
public static IActionResult ApiResult<T>(this Task<Result<T>> result) => ApiResult(result.Result); | ||
|
||
public static IActionResult ApiResult(this Result result) => new ObjectResult(result.Message) { StatusCode = (int)result.Status }; | ||
|
||
public static IActionResult ApiResult(this Task<Result> result) => ApiResult(result.Result); | ||
|
||
public static IActionResult ApiResult<T>(this T result) => new ObjectResult(result); | ||
|
||
public static IActionResult ApiResult<T>(this Task<T> result) => ApiResult(result.Result); | ||
} |
63 changes: 63 additions & 0 deletions
63
source/AspNetCore/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using Microsoft.AspNetCore.Mvc.Authorization; | ||
using Microsoft.AspNetCore.StaticFiles; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.OpenApi.Models; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace DotNetCore.AspNetCore; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IMvcBuilder AddAuthorizationPolicy(this IMvcBuilder builder) => builder.AddMvcOptions(options => options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()))); | ||
|
||
public static IServiceCollection AddCorsAllowAny(this IServiceCollection services) => services.AddCors(options => options.AddPolicy("AllowAny", policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); | ||
|
||
public static IServiceCollection AddFileExtensionContentTypeProvider(this IServiceCollection services) => services.AddSingleton<IContentTypeProvider, FileExtensionContentTypeProvider>(); | ||
|
||
public static IMvcBuilder AddJsonOptions(this IMvcBuilder builder) => builder.AddJsonOptions(options => | ||
{ | ||
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; | ||
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||
options.JsonSerializerOptions.Converters.Add(new JsonStringBoolConverter()); | ||
}); | ||
|
||
public static void AddSwaggerDefault(this IServiceCollection services) => services.AddSwaggerGen(ConfigureSwaggerGenOptions); | ||
|
||
public static IServiceCollection ConfigureFormOptionsMaxLengthLimit(this IServiceCollection services) => services.Configure<FormOptions>(options => | ||
{ | ||
options.ValueLengthLimit = int.MaxValue; | ||
options.MultipartBodyLengthLimit = int.MaxValue; | ||
}); | ||
|
||
private static void ConfigureSwaggerGenOptions(this SwaggerGenOptions options) | ||
{ | ||
options.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme, new OpenApiSecurityScheme | ||
{ | ||
Type = SecuritySchemeType.ApiKey, | ||
In = ParameterLocation.Header, | ||
Name = "Authorization" | ||
}); | ||
|
||
options.AddSecurityRequirement(new OpenApiSecurityRequirement | ||
{ | ||
{ | ||
new OpenApiSecurityScheme | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.SecurityScheme, | ||
Id = JwtBearerDefaults.AuthenticationScheme | ||
}, | ||
In = ParameterLocation.Header, | ||
Scheme = SecuritySchemeType.OAuth2.ToString(), | ||
Name = JwtBearerDefaults.AuthenticationScheme | ||
}, | ||
new List<string>() | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# DotNetCore.AspNetCore | ||
|
||
## Attributes | ||
|
||
### EnumAuthorizeAttribute | ||
|
||
```cs | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] | ||
public sealed class EnumAuthorizeAttribute : AuthorizeAttribute | ||
{ | ||
public EnumAuthorizeAttribute(params object[] roles) { } | ||
} | ||
``` | ||
|
||
## Extensions | ||
|
||
### ApplicationBuilderExtensions | ||
|
||
```cs | ||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static void UseCorsAllowAny(this IApplicationBuilder application) { } | ||
|
||
public static void UseException(this IApplicationBuilder application) { } | ||
|
||
public static void UseLocalization(this IApplicationBuilder application, params string[] cultures) { } | ||
|
||
public static void ConfigureFormOptions(this IServiceCollection services) { } | ||
} | ||
``` | ||
|
||
### BinaryFileExtensions | ||
|
||
```cs | ||
public static class BinaryFileExtensions | ||
{ | ||
public static IActionResult FileResult(this Task<BinaryFile> binaryFile) { } | ||
} | ||
``` | ||
|
||
### HttpRequestExtensions | ||
|
||
```cs | ||
public static class HttpRequestExtensions | ||
{ | ||
public static IList<BinaryFile> Files(this HttpRequest request) { } | ||
} | ||
``` | ||
|
||
### ResultExtensions | ||
|
||
```cs | ||
public static class ResultExtensions | ||
{ | ||
public static IActionResult ApiResult<T>(this Result<T> result) { } | ||
|
||
public static IActionResult ApiResult<T>(this Task<Result<T>> result) { } | ||
|
||
public static IActionResult ApiResult(this Result result) { } | ||
|
||
public static IActionResult ApiResult(this Task<Result> result) { } | ||
|
||
public static IActionResult ApiResult<T>(this T result) { } | ||
|
||
public static IActionResult ApiResult<T>(this Task<T> result) { } | ||
} | ||
``` | ||
|
||
### ServiceCollectionExtensions | ||
|
||
```cs | ||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IMvcBuilder AddAuthorizationPolicy(this IMvcBuilder builder) { } | ||
|
||
public static IServiceCollection AddCorsAllowAny(this IServiceCollection services) { } | ||
|
||
public static IServiceCollection AddFileExtensionContentTypeProvider(this IServiceCollection services) { } | ||
|
||
public static IMvcBuilder AddJsonOptions(this IMvcBuilder builder) { } | ||
|
||
public static void AddSwaggerDefault(this IServiceCollection services) { } | ||
|
||
public static IServiceCollection ConfigureFormOptionsMaxLengthLimit(this IServiceCollection services) { } | ||
} | ||
``` |
Oops, something went wrong.