增加异常定义和描述

This commit is contained in:
FalconFly 2024-04-16 10:59:44 +08:00
parent 498913bb25
commit 6a63035889
2 changed files with 22 additions and 2 deletions

View File

@ -2,7 +2,6 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -25,6 +24,7 @@ namespace Falcon.SugarApi.Plugin.Service
/// <param name="services">服务集合</param> /// <param name="services">服务集合</param>
/// <param name="config">应用程序配置</param> /// <param name="config">应用程序配置</param>
/// <param name="pluginNames">插件名称数组</param> /// <param name="pluginNames">插件名称数组</param>
/// <exception cref="FileNotFoundException"></exception>
/// <returns>服务集合</returns> /// <returns>服务集合</returns>
public static IServiceCollection AddPluginService(this IServiceCollection services,IConfiguration config,params string[] pluginNames) { public static IServiceCollection AddPluginService(this IServiceCollection services,IConfiguration config,params string[] pluginNames) {
var name = typeof(IServicePlugin).FullName; var name = typeof(IServicePlugin).FullName;
@ -63,6 +63,7 @@ namespace Falcon.SugarApi.Plugin.Service
/// <param name="services">服务集合</param> /// <param name="services">服务集合</param>
/// <param name="config">应用程序配置</param> /// <param name="config">应用程序配置</param>
/// <param name="plugins">插件程序集数组</param> /// <param name="plugins">插件程序集数组</param>
/// <exception cref="PluginExecAddServicesException"></exception>
/// <returns>服务集合</returns> /// <returns>服务集合</returns>
public static IServiceCollection AddPluginService(this IServiceCollection services,IConfiguration config,params Assembly[] plugins) { public static IServiceCollection AddPluginService(this IServiceCollection services,IConfiguration config,params Assembly[] plugins) {
var name = typeof(IServicePlugin).FullName; var name = typeof(IServicePlugin).FullName;
@ -86,7 +87,7 @@ namespace Falcon.SugarApi.Plugin.Service
obj.AddServices(services,config); obj.AddServices(services,config);
} }
catch(Exception ex) { catch(Exception ex) {
throw new Exception($"调用插件{type.FullName}.IServicePlugin.AddServices]方法时发生异常。",ex); throw new PluginExecAddServicesException(type,ex);
} }
} }
} }

View File

@ -0,0 +1,19 @@
using System;
namespace Falcon.SugarApi.Plugin.Service
{
/// <summary>
/// 插件执行AddServices方法时发生错误
/// </summary>
public class PluginExecAddServicesException:Exception
{
/// <summary>
/// 通过插件类型和异常类型引发异常
/// </summary>
/// <param name="type">插件注册类型</param>
/// <param name="innExecption">已发的异常</param>
public PluginExecAddServicesException(Type type,Exception innExecption)
: base($"调用插件{type.FullName}.IServicePlugin.AddServices]方法时发生异常。",innExecption) {
}
}
}