业务需求:A项目需要把B项目的控制器动态的加载进来
//将其他业务API放到指定目录下,进行统一绑定
private void BuilderController(IMvcBuilder mvcBuilder)
{
var controllerPath = $"{AppDomain.CurrentDomain.BaseDirectory}Controller\\";
if (!Directory.Exists(controllerPath))
{
return;
}
var pathFiles = Directory.GetFiles($"{AppDomain.CurrentDomain.BaseDirectory}Controller\\", "*.dll", SearchOption.AllDirectories);
var pathFilesLength = pathFiles.Length;
if (pathFilesLength > 0)
{
for (int i = 0; i < pathFilesLength; i++)
{
mvcBuilder.AddApplicationPart(Assembly.LoadFile(pathFiles[i]));
}
}
//如果,文件夹下,除了控制器之外,还有其他dll
//if (pathFilesLength <= 0)