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 assemblies = new List(); //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); } } }