You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1.4 KiB

using Easy.Options;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using PermissionManagement.Api.EF;
namespace PermissionManagement.Api.Realization;
public static class CustomExtension
{
public static void AddCustomAuthentication(this WebApplicationBuilder builder,string authorityUrl)
{
builder.Services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
options.Authority = authorityUrl;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false
};
});
}
public static void AddCustomDbContext(this WebApplicationBuilder builder)
{
var sqlConnectionString = builder.Configuration["ConnectionString"];
builder.Services.AddDbContext<PermissionManagementContext>(optionsBuilder =>
{
if (!string.IsNullOrEmpty(sqlConnectionString))
{
optionsBuilder.UseMySql(sqlConnectionString, ServerVersion.Parse("8.0.28-mysql"));
}
});
builder.Services.AddTransient<DbContext, PermissionManagementContext>();
builder.Services.Configure<SequentialGuidGeneratorOptions>(options =>
{
options.SequentialGuidType = Easy.Enums.SequentialGuidType.SequentialAsString;
});
}
}