netcore-blueprint 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BlueprintTemplate/Host.API/Extensions/DatabaseExtensions.cs +1 -1
- package/BlueprintTemplate/Host.API/Extensions/ModuleExtension.cs +34 -0
- package/BlueprintTemplate/Host.API/Extensions/ServiceCollectionExtensions.cs +1 -15
- package/BlueprintTemplate/Host.API/Extensions/ThirdPartyExtensions.cs +1 -5
- package/BlueprintTemplate/Host.API/Program.cs +1 -2
- package/BlueprintTemplate/ItemModule.API/ItemModule.API.csproj +1 -0
- package/BlueprintTemplate/ItemModule.API/ItemModule.cs +24 -0
- package/BlueprintTemplate/ItemModule.Core/ItemCoreDependencyInjection.cs +19 -0
- package/BlueprintTemplate/ItemModule.Infrastructure/{ItemDependencyInjection.cs → ItemInfraDependencyInjection.cs} +4 -10
- package/BlueprintTemplate/ItemModule.Infrastructure/Services/MySQLItemInfra.cs +1 -1
- package/BlueprintTemplate/README.md +13 -7
- package/BlueprintTemplate/Shared.Core/Interfaces/Modules/IModule.cs +14 -0
- package/BlueprintTemplate/Shared.Core/Shared.Core.csproj +1 -0
- package/BlueprintTemplate/Shared.Infrastructure/{DbInitializer.cs → Database/DbInitializer.cs} +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/{MyDbContext.cs → Database/MyDbContext.cs} +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/Migrations/20260131121133_SeedInitialData.Designer.cs +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/Migrations/MyDbContextModelSnapshot.cs +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/Services/MySQL/MySQLItemInfra.cs +1 -0
- package/BlueprintTemplate/User.API/UserModule.API.csproj +1 -0
- package/BlueprintTemplate/User.API/UserModule.cs +24 -0
- package/BlueprintTemplate/User.Core/UserCoreDependencyInjection.cs +16 -0
- package/BlueprintTemplate/User.Infrastructure/Services/MySQLUserInfra.cs +1 -1
- package/BlueprintTemplate/User.Infrastructure/{UserDependencyInjection.cs → UserInfraDependencyInjection.cs} +2 -5
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
using Shared.Core.Interfaces.Modules;
|
|
2
|
+
|
|
3
|
+
namespace Host.API.Extensions
|
|
4
|
+
{
|
|
5
|
+
public static class ModuleExtensions
|
|
6
|
+
{
|
|
7
|
+
public static IServiceCollection AddModules(
|
|
8
|
+
this IServiceCollection services,
|
|
9
|
+
IConfiguration config)
|
|
10
|
+
{
|
|
11
|
+
var modules = AppDomain.CurrentDomain
|
|
12
|
+
.GetAssemblies()
|
|
13
|
+
.SelectMany(a => a.GetTypes())
|
|
14
|
+
.Where(t => typeof(IModule).IsAssignableFrom(t)
|
|
15
|
+
&& !t.IsInterface
|
|
16
|
+
&& !t.IsAbstract)
|
|
17
|
+
.Select(t => (IModule)Activator.CreateInstance(t)!);
|
|
18
|
+
|
|
19
|
+
foreach (var module in modules)
|
|
20
|
+
{
|
|
21
|
+
// Enable/disable via config (optional V1)
|
|
22
|
+
module.Register(services, config);
|
|
23
|
+
|
|
24
|
+
services.AddControllers()
|
|
25
|
+
.AddApplicationPart(module.ApiAssembly);
|
|
26
|
+
|
|
27
|
+
services.AddAutoMapper(cfg => { }, module.MappingAssembly);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return services;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
@@ -12,9 +12,7 @@ namespace Host.API.Extensions
|
|
|
12
12
|
this IServiceCollection services,
|
|
13
13
|
IConfiguration configuration)
|
|
14
14
|
{
|
|
15
|
-
services.AddControllers()
|
|
16
|
-
.AddApplicationPart(typeof(UserController).Assembly)
|
|
17
|
-
.AddApplicationPart(typeof(ItemController).Assembly);
|
|
15
|
+
services.AddControllers();
|
|
18
16
|
|
|
19
17
|
services.AddEndpointsApiExplorer();
|
|
20
18
|
services.AddSwaggerGen();
|
|
@@ -33,19 +31,7 @@ namespace Host.API.Extensions
|
|
|
33
31
|
return services;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
public static IServiceCollection AddUserModule(this IServiceCollection services)
|
|
37
|
-
{
|
|
38
|
-
UserDependencyInjection.AddUserModuleInfra(services);
|
|
39
|
-
return services;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
34
|
public static IServiceCollection AddItemModule(this IServiceCollection services)
|
|
43
|
-
{
|
|
44
|
-
ItemDependencyInjection.AddItemModuleInfra(services);
|
|
45
|
-
return services;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public static IServiceCollection AddSharedModule(this IServiceCollection services)
|
|
49
35
|
{
|
|
50
36
|
SharedDependencyInjection.AddSharedInfrastructure(services);
|
|
51
37
|
return services;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
using Asp.Versioning;
|
|
2
|
-
using ItemModule.API.Mappers;
|
|
3
|
-
using UserModule.API.Mappers;
|
|
4
2
|
|
|
5
3
|
namespace Host.API.Extensions
|
|
6
4
|
{
|
|
@@ -9,9 +7,7 @@ namespace Host.API.Extensions
|
|
|
9
7
|
public static IServiceCollection AddThirdParty(this IServiceCollection services)
|
|
10
8
|
{
|
|
11
9
|
services.AddAutoMapper(
|
|
12
|
-
cfg => { }
|
|
13
|
-
typeof(DtoItemMappingProfile).Assembly,
|
|
14
|
-
typeof(DtoUserMappingProfile).Assembly
|
|
10
|
+
cfg => { }
|
|
15
11
|
);
|
|
16
12
|
|
|
17
13
|
services.AddApiVersioning(opt =>
|
|
@@ -9,9 +9,8 @@ builder.Services.AddApiCore(builder.Configuration);
|
|
|
9
9
|
builder.Services.AddThirdParty();
|
|
10
10
|
|
|
11
11
|
// Modules
|
|
12
|
-
builder.Services.AddUserModule();
|
|
13
12
|
builder.Services.AddItemModule();
|
|
14
|
-
builder.Services.
|
|
13
|
+
builder.Services.AddModules(builder.Configuration);
|
|
15
14
|
|
|
16
15
|
// Database
|
|
17
16
|
builder.Services.AddMySqlDatabase(builder.Configuration);
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
<ItemGroup>
|
|
22
22
|
<ProjectReference Include="..\ItemModule.Core\ItemModule.Core.csproj" />
|
|
23
|
+
<ProjectReference Include="..\ItemModule.Infrastructure\ItemModule.Infrastructure.csproj" />
|
|
23
24
|
<ProjectReference Include="..\Shared.Core\Shared.Core.csproj" />
|
|
24
25
|
</ItemGroup>
|
|
25
26
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
using ItemModule.API.Controllers.Public;
|
|
2
|
+
using ItemModule.API.Mappers;
|
|
3
|
+
using ItemModule.Core;
|
|
4
|
+
using ItemModule.Infrastructure;
|
|
5
|
+
using Microsoft.Extensions.Configuration;
|
|
6
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
7
|
+
using Shared.Core.Interfaces.Modules;
|
|
8
|
+
using System.Reflection;
|
|
9
|
+
|
|
10
|
+
namespace ItemModule.API
|
|
11
|
+
{
|
|
12
|
+
public class ItemModule : IModule
|
|
13
|
+
{
|
|
14
|
+
public string Name => "Item";
|
|
15
|
+
public void Register(IServiceCollection services, IConfiguration config)
|
|
16
|
+
{
|
|
17
|
+
ItemCoreDependencyInjection.AddModule(services);
|
|
18
|
+
ItemInfraDependencyInjection.AddModule(services);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public Assembly ApiAssembly => typeof(ItemController).Assembly;
|
|
22
|
+
public Assembly MappingAssembly => typeof(DtoItemMappingProfile).Assembly;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
using ItemModule.Core.Interfaces.API;
|
|
2
|
+
using ItemModule.Core.Services;
|
|
3
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
4
|
+
using Shared.Core.Interfaces.API;
|
|
5
|
+
using Shared.Core.Services;
|
|
6
|
+
|
|
7
|
+
namespace ItemModule.Core
|
|
8
|
+
{
|
|
9
|
+
public static class ItemCoreDependencyInjection
|
|
10
|
+
{
|
|
11
|
+
public static IServiceCollection AddModule(
|
|
12
|
+
this IServiceCollection services)
|
|
13
|
+
{
|
|
14
|
+
services.AddScoped(typeof(IItemService<>), typeof(ItemService<>));
|
|
15
|
+
services.AddScoped<IItemService, ItemService>();
|
|
16
|
+
return services;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
using ItemModule.Core.Interfaces.
|
|
2
|
-
using ItemModule.Core.Interfaces.SPI;
|
|
3
|
-
using ItemModule.Core.Services;
|
|
1
|
+
using ItemModule.Core.Interfaces.SPI;
|
|
4
2
|
using ItemModule.Infrastructure.Database;
|
|
5
3
|
using ItemModule.Infrastructure.Services;
|
|
6
4
|
using Microsoft.Extensions.DependencyInjection;
|
|
7
|
-
using Shared.Core.Interfaces.API;
|
|
8
5
|
using Shared.Core.Interfaces.SPI;
|
|
9
|
-
using Shared.Core.Services;
|
|
10
6
|
using Shared.Infrastructure.Services.MySQL;
|
|
11
7
|
|
|
12
8
|
namespace ItemModule.Infrastructure
|
|
13
9
|
{
|
|
14
|
-
public static class
|
|
10
|
+
public static class ItemInfraDependencyInjection
|
|
15
11
|
{
|
|
16
|
-
public static IServiceCollection
|
|
12
|
+
public static IServiceCollection AddModule(
|
|
17
13
|
this IServiceCollection services)
|
|
18
14
|
{
|
|
19
15
|
services.AddScoped<IModuleSeeder, Seeder>();
|
|
20
|
-
services.AddScoped(typeof(IItemService<>), typeof(ItemService<>));
|
|
21
|
-
services.AddScoped(typeof(IItemInfra<>), typeof(MySQLItemInfra<>));
|
|
22
16
|
services.AddScoped<IItemInfra, MySQLItemInfra>();
|
|
23
|
-
services.AddScoped
|
|
17
|
+
services.AddScoped(typeof(IItemInfra<>), typeof(MySQLItemInfra<>));
|
|
24
18
|
return services;
|
|
25
19
|
}
|
|
26
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
using ItemModule.Core.Entities;
|
|
2
2
|
using ItemModule.Core.Interfaces.SPI;
|
|
3
3
|
using Microsoft.Extensions.Logging;
|
|
4
|
-
using Shared.Infrastructure;
|
|
4
|
+
using Shared.Infrastructure.Database;
|
|
5
5
|
using Shared.Infrastructure.Services.MySQL;
|
|
6
6
|
|
|
7
7
|
namespace ItemModule.Infrastructure.Services
|
|
@@ -7,16 +7,22 @@
|
|
|
7
7
|
6. Tạo mới 1 module
|
|
8
8
|
- Copy lại thư mục item để thêm module mới
|
|
9
9
|
- Sửa lại tên và toàn bộ namespace
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
. Controller: .AddApplicationPart(typeof(ItemController).Assembly);
|
|
13
|
-
. Injection: ItemDependencyInjection.AddItemModuleInfra(services);
|
|
14
|
-
+ Đăng ký Mapping ở ThirdPartyExtensions.cs: typeof(DtoItemMappingProfile).Assembly,
|
|
15
|
-
+ Gọi ở Program.cs: builder.Services.AddItemModule();
|
|
10
|
+
- Bật tắt các module không cần thiết
|
|
11
|
+
- Bật tắt hoặc chuyển đổi DB nếu cần
|
|
16
12
|
|
|
17
13
|
7. Mock Data
|
|
18
14
|
- Tools → NuGet Package Manager → Package Manager Console
|
|
19
15
|
- Default project: catalog.Infra
|
|
20
16
|
- Xóa Migration cũ
|
|
21
17
|
- Add-Migration SeedInitialData
|
|
22
|
-
- Update-Database
|
|
18
|
+
- Update-Database
|
|
19
|
+
|
|
20
|
+
8. Todos
|
|
21
|
+
- Tách migration theo module
|
|
22
|
+
- Plug/ Unplug module (config)
|
|
23
|
+
- Plug/ Unplug database provider (config)
|
|
24
|
+
- Thêm chức năng tạo module qua script
|
|
25
|
+
|
|
26
|
+
(Chỉnh sửa khi làm Mock back-end)
|
|
27
|
+
- Channge DB to NoSQL
|
|
28
|
+
- Simple infra for DocumentDb and Lambda
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
using Microsoft.Extensions.Configuration;
|
|
2
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
3
|
+
using System.Reflection;
|
|
4
|
+
|
|
5
|
+
namespace Shared.Core.Interfaces.Modules
|
|
6
|
+
{
|
|
7
|
+
public interface IModule
|
|
8
|
+
{
|
|
9
|
+
string Name { get; }
|
|
10
|
+
void Register(IServiceCollection services, IConfiguration config);
|
|
11
|
+
Assembly ApiAssembly { get; }
|
|
12
|
+
Assembly MappingAssembly { get; }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
5
5
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
6
6
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
7
7
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
8
|
-
using Shared.Infrastructure;
|
|
8
|
+
using Shared.Infrastructure.Database;
|
|
9
9
|
|
|
10
10
|
#nullable disable
|
|
11
11
|
|
|
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
|
|
4
4
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
5
5
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
6
6
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
7
|
-
using Shared.Infrastructure;
|
|
7
|
+
using Shared.Infrastructure.Database;
|
|
8
8
|
|
|
9
9
|
#nullable disable
|
|
10
10
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
using Microsoft.Extensions.Configuration;
|
|
2
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
3
|
+
using Shared.Core.Interfaces.Modules;
|
|
4
|
+
using System.Reflection;
|
|
5
|
+
using UserModule.API.Controllers.Admin;
|
|
6
|
+
using UserModule.API.Mappers;
|
|
7
|
+
using UserModule.Core;
|
|
8
|
+
using UserModule.Infrastructure;
|
|
9
|
+
|
|
10
|
+
namespace UserModule.API
|
|
11
|
+
{
|
|
12
|
+
public class UserModule: IModule
|
|
13
|
+
{
|
|
14
|
+
public string Name => "User";
|
|
15
|
+
public void Register(IServiceCollection services, IConfiguration config)
|
|
16
|
+
{
|
|
17
|
+
UserCoreDependencyInjection.AddModule(services);
|
|
18
|
+
UserInfraDependencyInjection.AddModule(services);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public Assembly ApiAssembly => typeof(UserController).Assembly;
|
|
22
|
+
public Assembly MappingAssembly => typeof(DtoUserMappingProfile).Assembly;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
2
|
+
using UserModule.Core.Interfaces.API;
|
|
3
|
+
using UserModule.Core.Services;
|
|
4
|
+
|
|
5
|
+
namespace UserModule.Core
|
|
6
|
+
{
|
|
7
|
+
public static class UserCoreDependencyInjection
|
|
8
|
+
{
|
|
9
|
+
public static IServiceCollection AddModule(
|
|
10
|
+
this IServiceCollection services)
|
|
11
|
+
{
|
|
12
|
+
services.AddScoped<IUserService, UserService>();
|
|
13
|
+
return services;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
using Microsoft.Extensions.DependencyInjection;
|
|
2
2
|
using Shared.Core.Interfaces.SPI;
|
|
3
|
-
using UserModule.Core.Interfaces.API;
|
|
4
3
|
using UserModule.Core.Interfaces.SPI;
|
|
5
|
-
using UserModule.Core.Services;
|
|
6
4
|
using UserModule.Infrastructure.Database;
|
|
7
5
|
using UserModule.Infrastructure.Services;
|
|
8
6
|
|
|
9
7
|
namespace UserModule.Infrastructure
|
|
10
8
|
{
|
|
11
|
-
public static class
|
|
9
|
+
public static class UserInfraDependencyInjection
|
|
12
10
|
{
|
|
13
|
-
public static IServiceCollection
|
|
11
|
+
public static IServiceCollection AddModule(
|
|
14
12
|
this IServiceCollection services)
|
|
15
13
|
{
|
|
16
14
|
services.AddScoped<IModuleSeeder, Seeder>();
|
|
17
15
|
services.AddScoped<IUserInfra, MySQLUserInfra>();
|
|
18
|
-
services.AddScoped<IUserService, UserService>();
|
|
19
16
|
return services;
|
|
20
17
|
}
|
|
21
18
|
}
|