-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 Update CICD workflow to request required permissions.
- Loading branch information
1 parent
40276ff
commit bc4677a
Showing
6 changed files
with
125 additions
and
121 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 |
---|---|---|
|
@@ -9,6 +9,10 @@ on: | |
- LICENSE | ||
- README.md | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
|
||
build: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
<!-- For more info on central package management go to https://devblogs.microsoft.com/nuget/introducing-central-package-management/ --> | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Ardalis.GuardClauses" Version="4.0.1" /> | ||
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> | ||
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" /> | ||
<PackageVersion Include="Azure.Identity" Version="1.9.0" /> | ||
<PackageVersion Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageVersion Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" /> | ||
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.6.0" /> | ||
<PackageVersion Include="MediatR" Version="12.1.1" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.6.23329.11" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0-preview.7.23375.9" /> | ||
<!--#if (!UseApiOnly)--> | ||
<PackageVersion Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.0-preview.7.23375.9" /> | ||
<!--#endif--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.7.23375.4" /> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0-preview.7.23375.4" /> | ||
<!--#if (UseSQLite)--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-preview.7.23375.4" /> | ||
<!--#endif--> | ||
<!--#if (UseLocalDB)--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.7.23375.4" /> | ||
<!--#endif--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0-preview.7.23375.4" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.7.23375.6" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.7.23375.6" /> | ||
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" /> | ||
<PackageVersion Include="Moq" Version="4.18.4" /> | ||
<PackageVersion Include="NSwag.AspNetCore" Version="13.19.0" /> | ||
<PackageVersion Include="NSwag.MSBuild" Version="13.19.0" /> | ||
<PackageVersion Include="nunit" Version="3.13.3" /> | ||
<PackageVersion Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
<PackageVersion Include="Respawn" Version="6.1.0" /> | ||
<PackageVersion Include="Testcontainers.MsSql" Version="3.3.0" /> | ||
<PackageVersion Include="ZymLabs.NSwag.FluentValidation.AspNetCore" Version="0.6.2" /> | ||
<!--#if(!UseApiOnly)--> | ||
<PackageVersion Include="Microsoft.Playwright" Version="1.35.0" /> | ||
<PackageVersion Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" /> | ||
<PackageVersion Include="SpecFlow.NUnit" Version="3.9.74" /> | ||
<!--#endif--> | ||
</ItemGroup> | ||
<!-- For more info on central package management go to https://devblogs.microsoft.com/nuget/introducing-central-package-management/ --> | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Ardalis.GuardClauses" Version="4.0.1" /> | ||
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> | ||
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" /> | ||
<PackageVersion Include="Azure.Identity" Version="1.9.0" /> | ||
<PackageVersion Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageVersion Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" /> | ||
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.6.0" /> | ||
<PackageVersion Include="MediatR" Version="12.1.1" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.6.23329.11" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0-preview.7.23375.9" /> | ||
<!--#if (!UseApiOnly)--> | ||
<PackageVersion Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.0-preview.7.23375.9" /> | ||
<!--#endif--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.7.23375.4" /> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0-preview.7.23375.4" /> | ||
<!--#if (UseSQLite)--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-preview.7.23375.4" /> | ||
<!--#endif--> | ||
<!--#if (UseLocalDB)--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.7.23375.4" /> | ||
<!--#endif--> | ||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0-preview.7.23375.4" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.7.23375.6" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.7.23375.6" /> | ||
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" /> | ||
<PackageVersion Include="Moq" Version="4.18.4" /> | ||
<PackageVersion Include="NSwag.AspNetCore" Version="13.19.0" /> | ||
<PackageVersion Include="NSwag.MSBuild" Version="13.19.0" /> | ||
<PackageVersion Include="nunit" Version="3.13.3" /> | ||
<PackageVersion Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
<PackageVersion Include="Respawn" Version="6.1.0" /> | ||
<PackageVersion Include="Testcontainers.MsSql" Version="3.3.0" /> | ||
<PackageVersion Include="ZymLabs.NSwag.FluentValidation.AspNetCore" Version="0.6.2" /> | ||
<!--#if(!UseApiOnly)--> | ||
<PackageVersion Include="Microsoft.Playwright" Version="1.35.0" /> | ||
<PackageVersion Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" /> | ||
<PackageVersion Include="SpecFlow.NUnit" Version="3.9.74" /> | ||
<!--#endif--> | ||
</ItemGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
using CleanArchitecture.Application.Common.Interfaces; | ||
using CleanArchitecture.Domain.Constants; | ||
using CleanArchitecture.Infrastructure.Data; | ||
using CleanArchitecture.Infrastructure.Data.Interceptors; | ||
using CleanArchitecture.Infrastructure.Identity; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
public static class DependencyInjection | ||
{ | ||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
var connectionString = configuration.GetConnectionString("DefaultConnection"); | ||
|
||
Guard.Against.Null(connectionString, message: "Connection string 'DefaultConnection' not found."); | ||
|
||
services.AddScoped<ISaveChangesInterceptor, AuditableEntityInterceptor>(); | ||
services.AddScoped<ISaveChangesInterceptor, DispatchDomainEventsInterceptor>(); | ||
|
||
services.AddDbContext<ApplicationDbContext>((sp, options) => | ||
{ | ||
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>()); | ||
#if (UseSQLite) | ||
options.UseSqlite(connectionString); | ||
#else | ||
options.UseSqlServer(connectionString); | ||
#endif | ||
}); | ||
|
||
services.AddScoped<IApplicationDbContext>(provider => provider.GetRequiredService<ApplicationDbContext>()); | ||
|
||
services.AddScoped<ApplicationDbContextInitialiser>(); | ||
|
||
#if (UseApiOnly) | ||
services.AddAuthentication() | ||
.AddBearerToken(IdentityConstants.BearerScheme); | ||
|
||
services.AddAuthorizationBuilder(); | ||
|
||
services | ||
.AddIdentityCore<ApplicationUser>() | ||
.AddRoles<IdentityRole>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>() | ||
.AddApiEndpoints(); | ||
#else | ||
services | ||
.AddDefaultIdentity<ApplicationUser>() | ||
.AddRoles<IdentityRole>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>(); | ||
#endif | ||
|
||
services.AddSingleton(TimeProvider.System); | ||
services.AddTransient<IIdentityService, IdentityService>(); | ||
|
||
services.AddAuthorization(options => | ||
options.AddPolicy(Policies.CanPurge, policy => policy.RequireRole(Roles.Administrator))); | ||
|
||
return services; | ||
} | ||
} | ||
using CleanArchitecture.Application.Common.Interfaces; | ||
using CleanArchitecture.Domain.Constants; | ||
using CleanArchitecture.Infrastructure.Data; | ||
using CleanArchitecture.Infrastructure.Data.Interceptors; | ||
using CleanArchitecture.Infrastructure.Identity; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
public static class DependencyInjection | ||
{ | ||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
var connectionString = configuration.GetConnectionString("DefaultConnection"); | ||
|
||
Guard.Against.Null(connectionString, message: "Connection string 'DefaultConnection' not found."); | ||
|
||
services.AddScoped<ISaveChangesInterceptor, AuditableEntityInterceptor>(); | ||
services.AddScoped<ISaveChangesInterceptor, DispatchDomainEventsInterceptor>(); | ||
|
||
services.AddDbContext<ApplicationDbContext>((sp, options) => | ||
{ | ||
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>()); | ||
#if (UseSQLite) | ||
options.UseSqlite(connectionString); | ||
#else | ||
options.UseSqlServer(connectionString); | ||
#endif | ||
}); | ||
|
||
services.AddScoped<IApplicationDbContext>(provider => provider.GetRequiredService<ApplicationDbContext>()); | ||
|
||
services.AddScoped<ApplicationDbContextInitialiser>(); | ||
|
||
#if (UseApiOnly) | ||
services.AddAuthentication() | ||
.AddBearerToken(IdentityConstants.BearerScheme); | ||
|
||
services.AddAuthorizationBuilder(); | ||
|
||
services | ||
.AddIdentityCore<ApplicationUser>() | ||
.AddRoles<IdentityRole>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>() | ||
.AddApiEndpoints(); | ||
#else | ||
services | ||
.AddDefaultIdentity<ApplicationUser>() | ||
.AddRoles<IdentityRole>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>(); | ||
#endif | ||
|
||
services.AddSingleton(TimeProvider.System); | ||
services.AddTransient<IIdentityService, IdentityService>(); | ||
|
||
services.AddAuthorization(options => | ||
options.AddPolicy(Policies.CanPurge, policy => policy.RequireRole(Roles.Administrator))); | ||
|
||
return services; | ||
} | ||
} |