服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
18 小时以前 a960900364d19bbf0ad7923a57989609e7fce798
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.IO;
using System;
using System.Reflection;
using System.Linq;
using System.Text.RegularExpressions;
 
namespace Tiger.Api.Controllers
{
    public static class Extension
    {
        public static IMvcBuilder AddExtraControllers(this IMvcBuilder builder)
        {
            // 动态加载多个dll
            string[] assemblyPattern = new[] { "Tiger.Controllers([.].*)*.dll" };
 
            //List<Assembly> assemblies = new List<Assembly>();
            //assemblies.AddRange(
            //    Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll", SearchOption.AllDirectories)
            //                  .Where(filename => assemblyPattern.Any(pattern => Regex.IsMatch(filename, pattern)))
            //                  .Select(Assembly.LoadFrom)
            //);
 
            var assemblies = PluginManager.Load(AppDomain.CurrentDomain.BaseDirectory, "Tiger.Controllers([.].*)*.dll");
            foreach (var assembly in assemblies)
            {
                builder = builder.AddApplicationPart(assembly);
            }
 
            return builder;
 
            //var assembly = Assembly.Load("Tiger.Controllers.WMS");
            //return builder.AddApplicationPart(assembly);
        }
    }
}