https://github.com/dotnet9/codewf.aspnetcore.core
一个简易的ASP.NET Core核心库,支持模块化开发
https://github.com/dotnet9/codewf.aspnetcore.core
Last synced: about 1 year ago
JSON representation
一个简易的ASP.NET Core核心库,支持模块化开发
- Host: GitHub
- URL: https://github.com/dotnet9/codewf.aspnetcore.core
- Owner: dotnet9
- License: mit
- Created: 2024-06-18T01:55:33.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-18T06:07:10.000Z (almost 2 years ago)
- Last Synced: 2025-02-08T21:15:59.374Z (over 1 year ago)
- Language: C#
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CodeWF.AspNetCore.Core
一个简易的ASP.NET Core核心库,支持模块化开发。
安装NuGet包:
```shell
NuGet\Install-Package CodeWF.AspNetCore.Core -Version 1.0.0
```
创建模块类库,添加模块入口类:
```csharp
public class SampleModule : IModule
{
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app)
{
}
}
```
注入模块:
```csharp
using CodeWF.AspNetCore.Core;
using WebAPISample.Helpers;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
var moduleAssemblies = FileHelper.GetModuleAssemblies();
builder.Services.AddModules(moduleAssemblies);
var app = builder.Build();
app.UseAuthorization();
app.MapControllers();
app.UseModules();
app.Run();
```
读取模块工程程序集
```csharp
using CodeWF.AspNetCore.Core;
using System.Reflection;
namespace WebAPISample.Helpers
{
public static class FileHelper
{
public static Assembly[] GetModuleAssemblies()
{
return Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory), "*.dll")
.Select(Assembly.LoadFrom).Where(
assembly =>
assembly.GetTypes().Any(type => !type.IsAbstract
&& typeof(IModule).IsAssignableFrom(type))).ToArray();
}
}
}
```