-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: moved duplicate extension code to a shared extension (#32)
- Loading branch information
1 parent
2c9c77d
commit 6af44fc
Showing
9 changed files
with
119 additions
and
178 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
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
src/services/BookStore.Services.Shared/Extensions/IServiceCollectionSharedExtensions.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,64 @@ | ||
using FluentValidation; | ||
using FluentValidation.AspNetCore; | ||
using MicroElements.Swashbuckle.FluentValidation.AspNetCore; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace BookStore.Services.Shared.Extensions; | ||
|
||
public static class IServiceCollectionSharedExtensions | ||
{ | ||
public static IServiceCollection AddSwaggerServices( | ||
this IServiceCollection services | ||
) | ||
{ | ||
services | ||
.AddEndpointsApiExplorer(); | ||
|
||
services | ||
.AddSwaggerGen(options => | ||
{ | ||
options.CustomSchemaIds(type => | ||
type.DeclaringType is null | ||
? $"{type.Name}" | ||
: $"{type.DeclaringType?.Name}.{type.Name}"); | ||
} | ||
) | ||
.AddFluentValidationRulesToSwagger(); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddFluentValidationServices<T, U>( | ||
this IServiceCollection services | ||
) where U : AbstractValidator<T> | ||
{ | ||
services | ||
.AddValidatorsFromAssemblyContaining<U>(); | ||
|
||
services | ||
.AddFluentValidationAutoValidation(); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddDbServices<T>( | ||
this IServiceCollection services, | ||
IConfiguration configuration | ||
) where T : DbContext | ||
{ | ||
services | ||
.AddDbContext<T>(options => | ||
{ | ||
options | ||
.UseSqlServer( | ||
configuration | ||
.GetConnectionString("database") | ||
); | ||
} | ||
); | ||
|
||
return services; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/services/BookStore.Services.Shared/Extensions/WebApplicationSharedExtensions.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,40 @@ | ||
using BookStore.Services.Shared.Middleware; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace BookStore.Services.Shared.Extensions; | ||
|
||
public static class WebApplicationSharedExtensions | ||
{ | ||
public static WebApplication AddDevelopmentMiddleWare( | ||
this WebApplication app | ||
) | ||
{ | ||
app | ||
.UseSwagger(); | ||
|
||
app | ||
.UseSwaggerUI(); | ||
|
||
return app; | ||
} | ||
|
||
public static WebApplication AddCustomMiddleware( | ||
this WebApplication app | ||
) | ||
{ | ||
app | ||
.UseMiddleware<ExceptionMiddleware>(); | ||
|
||
return app; | ||
} | ||
|
||
public static WebApplication AddAuthMiddleWare( | ||
this WebApplication app | ||
) | ||
{ | ||
app | ||
.UseAuthorization(); | ||
|
||
return app; | ||
} | ||
} |