mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-04 00:35:47 +08:00
refactor: ai+人工重构优化 framework
This commit is contained in:
@@ -8,52 +8,81 @@ using Volo.Abp.Modularity;
|
||||
|
||||
namespace Yi.Framework.Core.Modularity;
|
||||
|
||||
[Dependency(ReplaceServices =true)]
|
||||
/// <summary>
|
||||
/// Yi框架模块管理器
|
||||
/// </summary>
|
||||
[Dependency(ReplaceServices = true)]
|
||||
public class YiModuleManager : ModuleManager, IModuleManager, ISingletonDependency
|
||||
{
|
||||
private readonly IModuleContainer _moduleContainer;
|
||||
private readonly IEnumerable<IModuleLifecycleContributor> _lifecycleContributors;
|
||||
private readonly ILogger<YiModuleManager> _logger;
|
||||
|
||||
public YiModuleManager(IModuleContainer moduleContainer, ILogger<YiModuleManager> logger, IOptions<AbpModuleLifecycleOptions> options, IServiceProvider serviceProvider) : base(moduleContainer, logger, options, serviceProvider)
|
||||
/// <summary>
|
||||
/// 初始化模块管理器
|
||||
/// </summary>
|
||||
public YiModuleManager(
|
||||
IModuleContainer moduleContainer,
|
||||
ILogger<YiModuleManager> logger,
|
||||
IOptions<AbpModuleLifecycleOptions> options,
|
||||
IServiceProvider serviceProvider)
|
||||
: base(moduleContainer, logger, options, serviceProvider)
|
||||
{
|
||||
_moduleContainer = moduleContainer;
|
||||
_logger = logger;
|
||||
_lifecycleContributors = options.Value.Contributors.Select(serviceProvider.GetRequiredService).Cast<IModuleLifecycleContributor>().ToArray();
|
||||
_lifecycleContributors = options.Value.Contributors
|
||||
.Select(serviceProvider.GetRequiredService)
|
||||
.Cast<IModuleLifecycleContributor>()
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化所有模块
|
||||
/// </summary>
|
||||
/// <param name="context">应用程序初始化上下文</param>
|
||||
public override async Task InitializeModulesAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
|
||||
_logger.LogDebug("==========模块Initialize初始化统计-跳过0ms模块==========");
|
||||
var total = 0;
|
||||
var watch =new Stopwatch();
|
||||
long totalTime = 0;
|
||||
|
||||
var moduleCount = 0;
|
||||
var stopwatch = new Stopwatch();
|
||||
var totalTime = 0L;
|
||||
|
||||
foreach (var contributor in _lifecycleContributors)
|
||||
{
|
||||
foreach (var module in _moduleContainer.Modules)
|
||||
{
|
||||
try
|
||||
{
|
||||
watch.Restart();
|
||||
stopwatch.Restart();
|
||||
await contributor.InitializeAsync(context, module.Instance);
|
||||
watch.Stop();
|
||||
totalTime += watch.ElapsedMilliseconds;
|
||||
total++;
|
||||
if (watch.ElapsedMilliseconds > 1)
|
||||
stopwatch.Stop();
|
||||
|
||||
totalTime += stopwatch.ElapsedMilliseconds;
|
||||
moduleCount++;
|
||||
|
||||
// 仅记录耗时超过1ms的模块
|
||||
if (stopwatch.ElapsedMilliseconds > 1)
|
||||
{
|
||||
_logger.LogDebug($"耗时-{watch.ElapsedMilliseconds}ms,已加载模块-{module.Assembly.GetName().Name}");
|
||||
_logger.LogDebug(
|
||||
"耗时-{Time}ms,已加载模块-{ModuleName}",
|
||||
stopwatch.ElapsedMilliseconds,
|
||||
module.Assembly.GetName().Name);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new AbpInitializationException($"An error occurred during the initialize {contributor.GetType().FullName} phase of the module {module.Type.AssemblyQualifiedName}: {ex.Message}. See the inner exception for details.", ex);
|
||||
throw new AbpInitializationException(
|
||||
$"模块 {module.Type.AssemblyQualifiedName} 在 {contributor.GetType().FullName} 阶段初始化失败: {ex.Message}",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation($"==========【{total}】个模块初始化执行完毕,总耗时【{totalTime}ms】==========");
|
||||
|
||||
_logger.LogInformation(
|
||||
"==========【{Count}】个模块初始化执行完毕,总耗时【{Time}ms】==========",
|
||||
moduleCount,
|
||||
totalTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user