|
|
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Hosting; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using EShopOnAbp.CatalogService.MongoDB; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Volo.Abp; |
|
|
|
@ -17,114 +18,111 @@ using Volo.Abp.Modularity; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
|
|
|
|
namespace EShopOnAbp.CatalogService |
|
|
|
namespace EShopOnAbp.CatalogService; |
|
|
|
|
|
|
|
[DependsOn( |
|
|
|
typeof(CatalogServiceHttpApiModule), |
|
|
|
typeof(CatalogServiceApplicationModule), |
|
|
|
typeof(CatalogServiceMongoDbModule), |
|
|
|
typeof(EShopOnAbpSharedHostingMicroservicesModule) |
|
|
|
)] |
|
|
|
public class CatalogServiceHttpApiHostModule : AbpModule |
|
|
|
{ |
|
|
|
[DependsOn( |
|
|
|
typeof(CatalogServiceHttpApiModule), |
|
|
|
typeof(CatalogServiceApplicationModule), |
|
|
|
typeof(CatalogServiceMongoDbModule), |
|
|
|
typeof(EShopOnAbpSharedHostingMicroservicesModule) |
|
|
|
)] |
|
|
|
public class CatalogServiceHttpApiHostModule : AbpModule |
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
JwtBearerConfigurationHelper.Configure(context, "CatalogService"); |
|
|
|
JwtBearerConfigurationHelper.Configure(context, "CatalogService"); |
|
|
|
|
|
|
|
SwaggerWithAuthConfigurationHelper.Configure( |
|
|
|
context: context, |
|
|
|
authority: configuration["AuthServer:Authority"], |
|
|
|
scopes: new Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */ |
|
|
|
SwaggerWithAuthConfigurationHelper.Configure( |
|
|
|
context: context, |
|
|
|
authority: configuration["AuthServer:Authority"], |
|
|
|
scopes: new |
|
|
|
Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */ |
|
|
|
{ |
|
|
|
{"CatalogService", "Catalog Service API"}, |
|
|
|
{"CatalogService", "Catalog Service API"} |
|
|
|
}, |
|
|
|
apiTitle: "Catalog Service API" |
|
|
|
); |
|
|
|
apiTitle: "Catalog 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(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<AbpAspNetCoreMvcOptions>(options => |
|
|
|
{ |
|
|
|
options.ConventionalControllers.Create(typeof(CatalogServiceApplicationModule).Assembly, opts => |
|
|
|
{ |
|
|
|
opts.RootPath = "catalog"; |
|
|
|
opts.RemoteServiceName = "Catalog"; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<AbpUnitOfWorkDefaultOptions>(options => |
|
|
|
context.Services.AddCors(options => |
|
|
|
{ |
|
|
|
options.AddDefaultPolicy(builder => |
|
|
|
{ |
|
|
|
//Standalone MongoDB servers don't support transactions
|
|
|
|
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; |
|
|
|
builder |
|
|
|
.WithOrigins( |
|
|
|
configuration["App:CorsOrigins"] |
|
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
|
|
|
.Select(o => o.Trim().RemovePostFix("/")) |
|
|
|
.ToArray() |
|
|
|
) |
|
|
|
.WithAbpExposedHeaders() |
|
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains() |
|
|
|
.AllowAnyHeader() |
|
|
|
.AllowAnyMethod() |
|
|
|
.AllowCredentials(); |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<AbpAntiForgeryOptions>(options => |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<AbpAspNetCoreMvcOptions>(options => |
|
|
|
{ |
|
|
|
options.ConventionalControllers.Create(typeof(CatalogServiceApplicationModule).Assembly, opts => |
|
|
|
{ |
|
|
|
options.AutoValidate = false; |
|
|
|
opts.RootPath = "catalog"; |
|
|
|
opts.RemoteServiceName = "Catalog"; |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
Configure<AbpUnitOfWorkDefaultOptions>(options => |
|
|
|
{ |
|
|
|
var app = context.GetApplicationBuilder(); |
|
|
|
var env = context.GetEnvironment(); |
|
|
|
//Standalone MongoDB servers don't support transactions
|
|
|
|
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; |
|
|
|
}); |
|
|
|
|
|
|
|
if (env.IsDevelopment()) |
|
|
|
{ |
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
} |
|
|
|
Configure<AbpAntiForgeryOptions>(options => { options.AutoValidate = false; }); |
|
|
|
} |
|
|
|
|
|
|
|
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", "Catalog Service API"); |
|
|
|
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); |
|
|
|
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); |
|
|
|
}); |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
app.UseAuditing(); |
|
|
|
app.UseUnitOfWork(); |
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
} |
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
var app = context.GetApplicationBuilder(); |
|
|
|
var env = context.GetEnvironment(); |
|
|
|
|
|
|
|
public override void OnPostApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
if (env.IsDevelopment()) |
|
|
|
{ |
|
|
|
using (var scope = context.ServiceProvider.CreateScope()) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync( |
|
|
|
() => scope.ServiceProvider |
|
|
|
.GetRequiredService<CatalogServiceDatabaseMigrationChecker>() |
|
|
|
.CheckAsync() |
|
|
|
); |
|
|
|
} |
|
|
|
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", "Catalog 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<CatalogServiceDatabaseMigrationChecker>() |
|
|
|
.CheckAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void OnPostApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(() => OnApplicationInitializationAsync(context)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |