netcore-blueprint 0.0.6 → 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.
Files changed (25) hide show
  1. package/BlueprintTemplate/Host.API/Extensions/DatabaseExtensions.cs +1 -1
  2. package/BlueprintTemplate/Host.API/Extensions/ModuleExtension.cs +34 -0
  3. package/BlueprintTemplate/Host.API/Extensions/ServiceCollectionExtensions.cs +1 -15
  4. package/BlueprintTemplate/Host.API/Extensions/ThirdPartyExtensions.cs +1 -5
  5. package/BlueprintTemplate/Host.API/Program.cs +1 -2
  6. package/BlueprintTemplate/ItemModule.API/ItemModule.API.csproj +1 -0
  7. package/BlueprintTemplate/ItemModule.API/ItemModule.cs +24 -0
  8. package/BlueprintTemplate/ItemModule.Core/ItemCoreDependencyInjection.cs +19 -0
  9. package/BlueprintTemplate/ItemModule.Infrastructure/{ItemDependencyInjection.cs → ItemInfraDependencyInjection.cs} +4 -10
  10. package/BlueprintTemplate/ItemModule.Infrastructure/Services/MySQLItemInfra.cs +1 -1
  11. package/BlueprintTemplate/README.md +13 -7
  12. package/BlueprintTemplate/Shared.Core/Interfaces/Modules/IModule.cs +14 -0
  13. package/BlueprintTemplate/Shared.Core/Shared.Core.csproj +1 -0
  14. package/BlueprintTemplate/Shared.Infrastructure/{DbInitializer.cs → Database/DbInitializer.cs} +1 -1
  15. package/BlueprintTemplate/Shared.Infrastructure/{MyDbContext.cs → Database/MyDbContext.cs} +1 -1
  16. package/BlueprintTemplate/Shared.Infrastructure/Migrations/20260131121133_SeedInitialData.Designer.cs +1 -1
  17. package/BlueprintTemplate/Shared.Infrastructure/Migrations/MyDbContextModelSnapshot.cs +1 -1
  18. package/BlueprintTemplate/Shared.Infrastructure/Services/MySQL/MySQLItemInfra.cs +1 -0
  19. package/BlueprintTemplate/User.API/UserModule.API.csproj +1 -0
  20. package/BlueprintTemplate/User.API/UserModule.cs +24 -0
  21. package/BlueprintTemplate/User.Core/UserCoreDependencyInjection.cs +16 -0
  22. package/BlueprintTemplate/User.Infrastructure/Services/MySQLUserInfra.cs +1 -1
  23. package/BlueprintTemplate/User.Infrastructure/{UserDependencyInjection.cs → UserInfraDependencyInjection.cs} +2 -5
  24. package/README.md +2 -19
  25. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  using Microsoft.EntityFrameworkCore;
2
- using Shared.Infrastructure;
2
+ using Shared.Infrastructure.Database;
3
3
 
4
4
  namespace Host.API.Extensions
5
5
  {
@@ -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.AddSharedModule();
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.API;
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 ItemDependencyInjection
10
+ public static class ItemInfraDependencyInjection
15
11
  {
16
- public static IServiceCollection AddItemModuleInfra(
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<IItemService, ItemService>();
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
- - Sửa lại các nội dung sau (Trong Host.API):
11
- + Đăng ServiceCollectionExtensions.cs:
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
+ }
@@ -8,6 +8,7 @@
8
8
 
9
9
  <ItemGroup>
10
10
  <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
11
+ <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.2" />
11
12
  </ItemGroup>
12
13
 
13
14
  </Project>
@@ -1,7 +1,7 @@
1
1
  using Microsoft.EntityFrameworkCore;
2
2
  using Shared.Core.Interfaces.SPI;
3
3
 
4
- namespace Shared.Infrastructure
4
+ namespace Shared.Infrastructure.Database
5
5
  {
6
6
  public static class DbInitializer
7
7
  {
@@ -1,7 +1,7 @@
1
1
  using Microsoft.EntityFrameworkCore;
2
2
  using Shared.Core.Interfaces.SPI;
3
3
 
4
- namespace Shared.Infrastructure
4
+ namespace Shared.Infrastructure.Database
5
5
  {
6
6
  public class MyDbContext : DbContext
7
7
  {
@@ -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
 
@@ -5,6 +5,7 @@ using Shared.Core.Enums;
5
5
  using Shared.Core.Exceptions;
6
6
  using Shared.Core.Interfaces.SPI;
7
7
  using Shared.Core.Shared.Models;
8
+ using Shared.Infrastructure.Database;
8
9
  using System.Linq.Expressions;
9
10
 
10
11
  namespace Shared.Infrastructure.Services.MySQL
@@ -3,6 +3,7 @@
3
3
  <ItemGroup>
4
4
  <ProjectReference Include="..\User.Core\UserModule.Core.csproj" />
5
5
  <ProjectReference Include="..\Shared.Core\Shared.Core.csproj" />
6
+ <ProjectReference Include="..\User.Infrastructure\UserModule.Infrastructure.csproj" />
6
7
  </ItemGroup>
7
8
 
8
9
  <ItemGroup>
@@ -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,5 +1,5 @@
1
1
  using Microsoft.Extensions.Logging;
2
- using Shared.Infrastructure;
2
+ using Shared.Infrastructure.Database;
3
3
  using Shared.Infrastructure.Services.MySQL;
4
4
  using UserModule.Core.Entities;
5
5
  using UserModule.Core.Interfaces.SPI;
@@ -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 UserDependencyInjection
9
+ public static class UserInfraDependencyInjection
12
10
  {
13
- public static IServiceCollection AddUserModuleInfra(
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
  }
package/README.md CHANGED
@@ -1,22 +1,5 @@
1
- How to make a blueprint (Ex: init-blueprint)
2
- 1. Change the name of the blueprint project in package.json file:
3
- Ex: "name": "init-blueprint",
4
- "bin": {
5
- "init-blueprint": "create.js"
6
- },
7
- 2. Copy the template into BlueprintTemplate. The template include:
8
- - Basic files
9
- - Add gitignore file and change it from .gitignore=> gitignore file
10
- 3. Add git to the blueprint, and change the root branch from master to main
11
- - rm -rf .git
12
- - Add git
13
- - git branch -m master main
14
- 4. Create new repo in git
15
- - Add environment variables into the git repo: Project > Settings > CI/CD > Variables
16
- + NPM_TOKEN: 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
17
- + PACKAGE_NAME: init-blueprint
18
- - push the blueprint to main branch
19
- 5. Use the lib from npm:
1
+ How to make a blueprint
2
+ 1. Use the lib from npm:
20
3
  - npm uninstall -g netcore-blueprint
21
4
  - npm install -g netcore-blueprint
22
5
  - npm list -g netcore-blueprint
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netcore-blueprint",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "A custom project blueprint",
5
5
  "main": "create.js",
6
6
  "bin": {