Browse Source

Product service initially completed.

pull/751/head
Halil ibrahim Kalkan 7 years ago
parent
commit
fe08ffe458
  1. 1
      .gitignore
  2. 0
      samples/MicroserviceDemo/applications/authserver/AuthServer.Host/EntityFrameworkCore/AuthServerDbContextFactory.cs
  3. 2
      samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminApp.Host.csproj
  4. 3
      samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminAppHostModule.cs
  5. 31
      samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Controllers/TestController.cs
  6. 5
      samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/appsettings.json
  7. 86
      samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ClientDemoService.cs
  8. 1
      samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemo.csproj
  9. 6
      samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemoModule.cs
  10. 7
      samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/appsettings.json
  11. 13
      samples/MicroserviceDemo/microservices/product/ProductService.Host/Controllers/HomeController.cs
  12. 29
      samples/MicroserviceDemo/microservices/product/ProductService.Host/EntityFrameworkCore/AuthServerDbContextFactory.cs
  13. 23
      samples/MicroserviceDemo/microservices/product/ProductService.Host/EntityFrameworkCore/ProductServiceMigrationDbContext.cs
  14. 71
      samples/MicroserviceDemo/microservices/product/ProductService.Host/Migrations/20190121115908_Initial.Designer.cs
  15. 48
      samples/MicroserviceDemo/microservices/product/ProductService.Host/Migrations/20190121115908_Initial.cs
  16. 69
      samples/MicroserviceDemo/microservices/product/ProductService.Host/Migrations/ProductServiceMigrationDbContextModelSnapshot.cs
  17. 4
      samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductService.Host.csproj
  18. 4
      samples/MicroserviceDemo/microservices/product/ProductService.Host/appsettings.json
  19. 2
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/ProductManagementConsts.cs
  20. 2
      samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EntityFrameworkCore/ProductManagementDbContextModelCreatingExtensions.cs
  21. 0
      samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi.Client/ProductManagement/ProductManagementHttpApiClientModule.cs

1
.gitignore

@ -288,3 +288,4 @@ templates/mvc/src/MyCompanyName\.MyProjectName\.Web/package-lock\.json
samples/MicroserviceDemo/applications/authserver/AuthServer.Host/Logs/logs.txt
samples/MicroserviceDemo/microservices/identity/IdentityService.Host/Logs/logs.txt
samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Logs/logs.txt
samples/MicroserviceDemo/microservices/product/ProductService.Host/Logs/logs.txt

0
samples/MicroserviceDemo/applications/authserver/AuthServer.Host/EntityFrameworkCore/MyProjectNameMigrationsDbContextFactory.cs → samples/MicroserviceDemo/applications/authserver/AuthServer.Host/EntityFrameworkCore/AuthServerDbContextFactory.cs

2
samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminApp.Host.csproj

@ -27,6 +27,8 @@
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.csproj" />
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi.Client\Volo.Abp.Identity.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.Identity.Web\Volo.Abp.Identity.Web.csproj" />
<ProjectReference Include="..\..\..\modules\product\src\ProductManagement.HttpApi.Client\ProductManagement.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\modules\product\src\ProductManagement.Web\ProductManagement.Web.csproj" />
</ItemGroup>
<ItemGroup>

3
samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminAppHostModule.cs

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using ProductManagement;
using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp;
using Volo.Abp.AspNetCore.Authentication.OAuth;
@ -23,6 +24,8 @@ namespace BackendAdminApp.Host
typeof(AbpHttpClientIdentityModelModule),
typeof(AbpIdentityHttpApiClientModule),
typeof(AbpIdentityWebModule),
typeof(ProductManagementHttpApiClientModule),
typeof(ProductManagementWebModule),
typeof(AbpAspNetCoreMvcUiBasicThemeModule)
)]
public class BackendAdminAppHostModule : AbpModule

31
samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Controllers/TestController.cs

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Json;
namespace BackendAdminApp.Host.Controllers
{
public class TestController : AbpController
{
private readonly IJsonSerializer _jsonSerializer;
public TestController(IJsonSerializer jsonSerializer)
{
_jsonSerializer = jsonSerializer;
}
[HttpGet]
public async Task<ActionResult> Index()
{
var newLine = Environment.NewLine + Environment.NewLine;
return Content(
"Claims: " + User.Claims.Select(c => $"{c.Type} = {c.Value}").JoinAsString(" | ") + newLine +
"CurrentUser: " + _jsonSerializer.Serialize(CurrentUser) + newLine
);
}
}
}

5
samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/appsettings.json

@ -1,8 +1,11 @@
{
"RemoteServices": {
"Default": {
"AbpIdentity": {
"BaseUrl": "http://localhost:63568/"
},
"ProductManagement": {
"BaseUrl": "http://localhost:60244/"
},
"AbpMvcClient": {
"BaseUrl": "http://localhost:63568/"
}

86
samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ClientDemoService.cs

@ -1,4 +1,5 @@
using System;
using ProductManagement;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
@ -10,20 +11,24 @@ namespace ConsoleClientDemo
public class ClientDemoService : ITransientDependency
{
private readonly IIdentityUserAppService _userAppService;
private readonly IProductAppService _productAppService;
private readonly IIdentityModelHttpClientAuthenticator _authenticator;
public ClientDemoService(
IIdentityUserAppService userAppService,
IProductAppService productAppService,
IIdentityModelHttpClientAuthenticator authenticator)
{
_userAppService = userAppService;
_authenticator = authenticator;
_productAppService = productAppService;
}
public async Task RunAsync()
{
await TestWithHttpClient();
await TestIdentityService();
await TestProductService();
}
/// <summary>
@ -32,23 +37,31 @@ namespace ConsoleClientDemo
/// </summary>
private async Task TestWithHttpClient()
{
Console.WriteLine("*** TestWithHttpClient ***");
Console.WriteLine();
Console.WriteLine("*** TestWithHttpClient ************************************");
using (var client = new HttpClient())
try
{
await _authenticator.AuthenticateAsync(client);
var response = await client.GetAsync("http://localhost:63568/Test");
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
}
else
using (var client = new HttpClient())
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
await _authenticator.AuthenticateAsync(client);
var response = await client.GetAsync("http://localhost:63568/Test");
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
}
else
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
/// <summary>
@ -60,14 +73,51 @@ namespace ConsoleClientDemo
/// </summary>
private async Task TestIdentityService()
{
var output = await _userAppService.GetListAsync(new GetIdentityUsersInput());
Console.WriteLine();
Console.WriteLine("*** TestIdentityService ************************************");
try
{
var output = await _userAppService.GetListAsync(new GetIdentityUsersInput());
Console.WriteLine("*** TestIdentityService ***");
Console.WriteLine("Total user count: " + output.TotalCount);
Console.WriteLine("Total user count: " + output.TotalCount);
foreach (var user in output.Items)
foreach (var user in output.Items)
{
Console.WriteLine($"- UserName={user.UserName}, Email={user.Email}, Name={user.Name}, Surname={user.Surname}");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
/// <summary>
/// Shows how to use application service interfaces (IProductAppService in this sample)
/// to call a remote service which is possible by the dynamic http client proxy system.
/// No need to use IIdentityModelHttpClientAuthenticator since the dynamic http client proxy
/// system internally uses it. You just inject a service (IProductAppService)
/// and call a method (GetListAsync) like a local method.
/// </summary>
private async Task TestProductService()
{
Console.WriteLine();
Console.WriteLine("*** TestProductService ************************************");
try
{
var output = await _productAppService.GetListAsync();
Console.WriteLine("Total product count: " + output.Items.Count);
foreach (var product in output.Items)
{
Console.WriteLine($"- Code={product.Code}, Name={product.Name}, Price={product.Price}, StockCount={product.StockCount}");
}
}
catch (Exception e)
{
Console.WriteLine($"- UserName={user.UserName}, Email={user.Email}, Name={user.Name}, Surname={user.Surname}");
Console.WriteLine(e);
}
}
}

1
samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemo.csproj

@ -14,6 +14,7 @@
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj" />
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi.Client\Volo.Abp.Identity.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\modules\product\src\ProductManagement.HttpApi.Client\ProductManagement.HttpApi.Client.csproj" />
</ItemGroup>
<ItemGroup>

6
samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemoModule.cs

@ -1,4 +1,5 @@
using Volo.Abp.Autofac;
using ProductManagement;
using Volo.Abp.Autofac;
using Volo.Abp.Http.Client.IdentityModel;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
@ -8,7 +9,8 @@ namespace ConsoleClientDemo
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpHttpClientIdentityModelModule),
typeof(AbpIdentityHttpApiClientModule)
typeof(AbpIdentityHttpApiClientModule),
typeof(ProductManagementHttpApiClientModule)
)]
public class ConsoleClientDemoModule : AbpModule
{

7
samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/appsettings.json

@ -1,7 +1,10 @@
{
"RemoteServices": {
"Default": {
"AbpIdentity": {
"BaseUrl": "http://localhost:63568/"
},
"ProductManagement": {
"BaseUrl": "http://localhost:60244/"
}
},
"IdentityClients": {
@ -12,7 +15,7 @@
"UserName": "admin",
"UserPassword": "1q2w3E*",
"Authority": "http://localhost:64999",
"Scope": "IdentityService"
"Scope": "IdentityService ProductService"
}
}
}

13
samples/MicroserviceDemo/microservices/product/ProductService.Host/Controllers/HomeController.cs

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
namespace ProductService.Host.Controllers
{
public class HomeController : AbpController
{
public ActionResult Index()
{
return Redirect("/swagger");
}
}
}

29
samples/MicroserviceDemo/microservices/product/ProductService.Host/EntityFrameworkCore/AuthServerDbContextFactory.cs

@ -0,0 +1,29 @@
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
namespace ProductService.Host.EntityFrameworkCore
{
public class ProductServiceMigrationDbContextFactory : IDesignTimeDbContextFactory<ProductServiceMigrationDbContext>
{
public ProductServiceMigrationDbContext CreateDbContext(string[] args)
{
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<ProductServiceMigrationDbContext>()
.UseSqlServer(configuration.GetConnectionString("ProductManagement"));
return new ProductServiceMigrationDbContext(builder.Options);
}
private static IConfigurationRoot BuildConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false);
return builder.Build();
}
}
}

23
samples/MicroserviceDemo/microservices/product/ProductService.Host/EntityFrameworkCore/ProductServiceMigrationDbContext.cs

@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using ProductManagement.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace ProductService.Host.EntityFrameworkCore
{
public class ProductServiceMigrationDbContext : AbpDbContext<ProductServiceMigrationDbContext>
{
public ProductServiceMigrationDbContext(
DbContextOptions<ProductServiceMigrationDbContext> options
) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ConfigureProductManagement();
}
}
}

71
samples/MicroserviceDemo/microservices/product/ProductService.Host/Migrations/20190121115908_Initial.Designer.cs

@ -0,0 +1,71 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ProductService.Host.EntityFrameworkCore;
namespace ProductService.Host.Migrations
{
[DbContext(typeof(ProductServiceMigrationDbContext))]
[Migration("20190121115908_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ProductManagement.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(32);
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(256);
b.Property<float>("Price");
b.Property<int>("StockCount");
b.HasKey("Id");
b.HasIndex("Code");
b.HasIndex("Name");
b.ToTable("PmProducts");
});
#pragma warning restore 612, 618
}
}
}

48
samples/MicroserviceDemo/microservices/product/ProductService.Host/Migrations/20190121115908_Initial.cs

@ -0,0 +1,48 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ProductService.Host.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PmProducts",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
ExtraProperties = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
CreationTime = table.Column<DateTime>(nullable: false),
CreatorId = table.Column<Guid>(nullable: true),
LastModificationTime = table.Column<DateTime>(nullable: true),
LastModifierId = table.Column<Guid>(nullable: true),
Code = table.Column<string>(maxLength: 32, nullable: false),
Name = table.Column<string>(maxLength: 256, nullable: false),
Price = table.Column<float>(nullable: false),
StockCount = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PmProducts", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_PmProducts_Code",
table: "PmProducts",
column: "Code");
migrationBuilder.CreateIndex(
name: "IX_PmProducts_Name",
table: "PmProducts",
column: "Name");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PmProducts");
}
}
}

69
samples/MicroserviceDemo/microservices/product/ProductService.Host/Migrations/ProductServiceMigrationDbContextModelSnapshot.cs

@ -0,0 +1,69 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ProductService.Host.EntityFrameworkCore;
namespace ProductService.Host.Migrations
{
[DbContext(typeof(ProductServiceMigrationDbContext))]
partial class ProductServiceMigrationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ProductManagement.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(32);
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(256);
b.Property<float>("Price");
b.Property<int>("StockCount");
b.HasKey("Id");
b.HasIndex("Code");
b.HasIndex("Name");
b.ToTable("PmProducts");
});
#pragma warning restore 612, 618
}
}
}

4
samples/MicroserviceDemo/microservices/product/ProductService.Host/ProductService.Host.csproj

@ -37,4 +37,8 @@
<None Remove="Logs\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Migrations\20190121115804_Initial.cs" />
</ItemGroup>
</Project>

4
samples/MicroserviceDemo/microservices/product/ProductService.Host/appsettings.json

@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=MsDemo_Product;Trusted_Connection=True;MultipleActiveResultSets=true",
"Default": "Server=localhost;Database=MsDemo_Identity;Trusted_Connection=True;MultipleActiveResultSets=true",
"ProductManagement": "Server=localhost;Database=MsDemo_ProductManagement;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
@ -9,4 +9,4 @@
}
},
"AllowedHosts": "*"
}
}

2
samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/ProductManagementConsts.cs

@ -2,7 +2,7 @@
{
public static class ProductManagementConsts
{
public const string DefaultDbTablePrefix = "ProductManagement";
public const string DefaultDbTablePrefix = "Pm";
public const string DefaultDbSchema = null;
}

2
samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EntityFrameworkCore/ProductManagementDbContextModelCreatingExtensions.cs

@ -21,6 +21,8 @@ namespace ProductManagement.EntityFrameworkCore
{
b.ToTable(options.TablePrefix + "Products", options.Schema);
b.ConfigureConcurrencyStamp();
b.ConfigureExtraProperties();
b.ConfigureAudited();
b.Property(x => x.Code).IsRequired().HasMaxLength(ProductConsts.MaxCodeLength);

0
samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi.Client/MyCompanyName/ProductManagement/ProductManagementHttpApiClientModule.cs → samples/MicroserviceDemo/modules/product/src/ProductManagement.HttpApi.Client/ProductManagement/ProductManagementHttpApiClientModule.cs

Loading…
Cancel
Save