diff --git a/samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductService.Host.csproj b/samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductService.Host.csproj
index 845371e352..7c4b669ef7 100644
--- a/samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductService.Host.csproj
+++ b/samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductService.Host.csproj
@@ -25,6 +25,9 @@
+
+
+
diff --git a/samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductServiceHostModule.cs b/samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductServiceHostModule.cs
new file mode 100644
index 0000000000..d946556279
--- /dev/null
+++ b/samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductServiceHostModule.cs
@@ -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(options =>
+ {
+ options.Languages.Add(new LanguageInfo("en", "en", "English"));
+ });
+
+ Configure(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();
+ }
+ }
+}
diff --git a/samples/MicroserviceDemo/microservices/product/ProductService.Host/Program.cs b/samples/MicroserviceDemo/microservices/product/ProductService.Host/Program.cs
index a3d9e97eca..a12f96d9b1 100644
--- a/samples/MicroserviceDemo/microservices/product/ProductService.Host/Program.cs
+++ b/samples/MicroserviceDemo/microservices/product/ProductService.Host/Program.cs
@@ -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();
+ public static IWebHost BuildWebHostInternal(string[] args) =>
+ new WebHostBuilder()
+ .UseKestrel()
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .UseIISIntegration()
+ .UseStartup()
+ .UseSerilog()
+ .Build();
}
}
diff --git a/samples/MicroserviceDemo/microservices/product/ProductService.Host/Startup.cs b/samples/MicroserviceDemo/microservices/product/ProductService.Host/Startup.cs
index 8ddcd3dca6..7734e291e6 100644
--- a/samples/MicroserviceDemo/microservices/product/ProductService.Host/Startup.cs
+++ b/samples/MicroserviceDemo/microservices/product/ProductService.Host/Startup.cs
@@ -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(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();
}
}
}
diff --git a/samples/MicroserviceDemo/microservices/product/ProductService.Host/appsettings.json b/samples/MicroserviceDemo/microservices/product/ProductService.Host/appsettings.json
index da1dd42ca3..3235e37aa7 100644
--- a/samples/MicroserviceDemo/microservices/product/ProductService.Host/appsettings.json
+++ b/samples/MicroserviceDemo/microservices/product/ProductService.Host/appsettings.json
@@ -1,6 +1,7 @@
{
"ConnectionStrings": {
- "Default": "Server=localhost;Database=MsDemo_Product;Trusted_Connection=True;MultipleActiveResultSets=true"
+ "Default": "Server=localhost;Database=MsDemo_Product;Trusted_Connection=True;MultipleActiveResultSets=true",
+ "ProductManagement": "Server=localhost;Database=MsDemo_ProductManagement;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement.Application.Contracts.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement.Application.Contracts.csproj
index d5b19038ca..1ff3221ba4 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement.Application.Contracts.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement.Application.Contracts.csproj
@@ -6,8 +6,8 @@
+
-
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement.Application.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement.Application.csproj
index 4bb3077928..92dedac429 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement.Application.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement.Application.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement.Domain.Shared.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement.Domain.Shared.csproj
index e5152da50c..e694ad7425 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement.Domain.Shared.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain.Shared/ProductManagement.Domain.Shared.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement.Domain.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement.Domain.csproj
index 961598b366..217120e629 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement.Domain.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement.Domain.csproj
@@ -6,9 +6,9 @@
+
+
-
-
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement.EntityFrameworkCore.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement.EntityFrameworkCore.csproj
index 0f0c87fd2a..4f68f44812 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement.EntityFrameworkCore.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement.EntityFrameworkCore.csproj
@@ -6,8 +6,8 @@
+
-
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi.Client/ProductManagement.HttpApi.Client.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi.Client/ProductManagement.HttpApi.Client.csproj
index 9fc9605253..3da908e809 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi.Client/ProductManagement.HttpApi.Client.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi.Client/ProductManagement.HttpApi.Client.csproj
@@ -6,8 +6,8 @@
+
-
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi/ProductManagement.HttpApi.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi/ProductManagement.HttpApi.csproj
index 303e86c328..fc5dca6d2e 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi/ProductManagement.HttpApi.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi/ProductManagement.HttpApi.csproj
@@ -6,8 +6,8 @@
+
-
diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagement.Web.csproj b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagement.Web.csproj
index 578fff59a8..c253d73404 100644
--- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagement.Web.csproj
+++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Web/ProductManagement.Web.csproj
@@ -14,20 +14,16 @@
-
-
-
-
+
+
-
-
diff --git a/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement.TestBase.csproj b/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement.TestBase.csproj
index 475346d060..01a1ddb479 100644
--- a/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement.TestBase.csproj
+++ b/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement.TestBase.csproj
@@ -6,9 +6,9 @@
-
-
-
+
+
+