mirror of https://github.com/abpframework/abp.git
14 changed files with 147 additions and 47 deletions
@ -0,0 +1,84 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using ProductManagement; |
|||
using ProductManagement.EntityFrameworkCore; |
|||
using Swashbuckle.AspNetCore.Swagger; |
|||
using Volo.Abp; |
|||
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore.SqlServer; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
|||
using Volo.Abp.Security.Claims; |
|||
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
|||
|
|||
namespace ProductService.Host |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpEntityFrameworkCoreSqlServerModule), |
|||
typeof(AbpAuditLoggingEntityFrameworkCoreModule), |
|||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
|||
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
|||
typeof(ProductManagementApplicationModule), |
|||
typeof(ProductManagementHttpApiModule), |
|||
typeof(ProductManagementEntityFrameworkCoreModule) |
|||
)] |
|||
public class ProductServiceHostModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddAuthentication("Bearer") |
|||
.AddIdentityServerAuthentication(options => |
|||
{ |
|||
options.Authority = "http://localhost:64999"; |
|||
options.RequireHttpsMetadata = false; |
|||
options.ApiName = "ProductService"; |
|||
|
|||
//TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation)
|
|||
options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; |
|||
options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; |
|||
options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; |
|||
options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; |
|||
options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; |
|||
options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; |
|||
options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; |
|||
}); |
|||
|
|||
context.Services.AddSwaggerGen(options => |
|||
{ |
|||
options.SwaggerDoc("v1", new Info {Title = "Product Service API", Version = "v1"}); |
|||
options.DocInclusionPredicate((docName, description) => true); |
|||
options.CustomSchemaIds(type => type.FullName); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|||
}); |
|||
|
|||
Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.UseSqlServer(); |
|||
}); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
var app = context.GetApplicationBuilder(); |
|||
|
|||
app.UseVirtualFiles(); |
|||
app.UseAuthentication(); |
|||
app.UseAbpRequestLocalization(); //TODO: localization?
|
|||
app.UseSwagger(); |
|||
app.UseSwaggerUI(options => |
|||
{ |
|||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Product Service API"); |
|||
}); |
|||
app.UseAuditing(); |
|||
app.UseMvcWithDefaultRouteAndArea(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,24 +1,46 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.Logging; |
|||
using Serilog; |
|||
using Serilog.Events; |
|||
|
|||
namespace ProductService.Host |
|||
{ |
|||
public class Program |
|||
{ |
|||
public static void Main(string[] args) |
|||
public static int Main(string[] args) |
|||
{ |
|||
CreateWebHostBuilder(args).Build().Run(); |
|||
Log.Logger = new LoggerConfiguration() |
|||
.MinimumLevel.Debug() |
|||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
|||
.Enrich.FromLogContext() |
|||
.WriteTo.File("Logs/logs.txt") |
|||
.CreateLogger(); |
|||
|
|||
try |
|||
{ |
|||
Log.Information("Starting IdentityService.Host."); |
|||
BuildWebHostInternal(args).Run(); |
|||
return 0; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.Fatal(ex, "IdentityService.Host terminated unexpectedly!"); |
|||
return 1; |
|||
} |
|||
finally |
|||
{ |
|||
Log.CloseAndFlush(); |
|||
} |
|||
} |
|||
|
|||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => |
|||
WebHost.CreateDefaultBuilder(args) |
|||
.UseStartup<Startup>(); |
|||
public static IWebHost BuildWebHostInternal(string[] args) => |
|||
new WebHostBuilder() |
|||
.UseKestrel() |
|||
.UseContentRoot(Directory.GetCurrentDirectory()) |
|||
.UseIISIntegration() |
|||
.UseStartup<Startup>() |
|||
.UseSerilog() |
|||
.Build(); |
|||
} |
|||
} |
|||
|
|||
@ -1,34 +1,28 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace ProductService.Host |
|||
{ |
|||
public class Startup |
|||
{ |
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
|||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
|||
public void ConfigureServices(IServiceCollection services) |
|||
public IServiceProvider ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<ProductServiceHostModule>(options => |
|||
{ |
|||
options.UseAutofac(); |
|||
options.Configuration.UserSecretsAssembly = typeof(Startup).Assembly; |
|||
}); |
|||
|
|||
return services.BuildServiceProviderFromFactory(); |
|||
} |
|||
|
|||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) |
|||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
|||
{ |
|||
if (env.IsDevelopment()) |
|||
{ |
|||
app.UseDeveloperExceptionPage(); |
|||
} |
|||
|
|||
app.Run(async (context) => |
|||
{ |
|||
await context.Response.WriteAsync("Hello World!"); |
|||
}); |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue