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.
105 lines
3.7 KiB
105 lines
3.7 KiB
using EShopOnAbp.PaymentService.DbMigrations;
|
|
using EShopOnAbp.PaymentService.EntityFrameworkCore;
|
|
using EShopOnAbp.Shared.Hosting.AspNetCore;
|
|
using EShopOnAbp.Shared.Hosting.Microservices;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Modularity;
|
|
|
|
namespace EShopOnAbp.PaymentService;
|
|
|
|
[DependsOn(
|
|
typeof(PaymentServiceApplicationModule),
|
|
typeof(PaymentServiceEntityFrameworkCoreModule),
|
|
typeof(PaymentServiceHttpApiModule),
|
|
typeof(EShopOnAbpSharedHostingMicroservicesModule)
|
|
)]
|
|
public class PaymentServiceHttpApiHostModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
|
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
JwtBearerConfigurationHelper.Configure(context, "PaymentService");
|
|
|
|
SwaggerConfigurationHelper.ConfigureWithAuth(
|
|
context: context,
|
|
authority: configuration["AuthServer:Authority"],
|
|
scopes: new
|
|
Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
|
|
{
|
|
{"PaymentService", "Payment Service API"}
|
|
},
|
|
apiTitle: "Payment Service API"
|
|
);
|
|
|
|
context.Services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(builder =>
|
|
{
|
|
builder
|
|
.WithOrigins(
|
|
configuration["App:CorsOrigins"]
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(o => o.Trim().RemovePostFix("/"))
|
|
.ToArray()
|
|
)
|
|
.WithAbpExposedHeaders()
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
var env = context.GetEnvironment();
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseCorrelationId();
|
|
app.UseCors();
|
|
app.UseAbpRequestLocalization();
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAbpClaimsMap();
|
|
app.UseAuthorization();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(options =>
|
|
{
|
|
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Payment Service API");
|
|
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
|
|
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
|
|
});
|
|
app.UseAbpSerilogEnrichers();
|
|
app.UseAuditing();
|
|
app.UseUnitOfWork();
|
|
app.UseConfiguredEndpoints();
|
|
}
|
|
|
|
public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context)
|
|
{
|
|
await context.ServiceProvider
|
|
.GetRequiredService<PaymentServiceDatabaseMigrationChecker>()
|
|
.CheckAndApplyDatabaseMigrationsAsync();
|
|
}
|
|
}
|