Skip to content

Commit

Permalink
向容器注入IEventProvider和ICommandClient,方便向星尘平台上报日志,以及注册应用命令(星尘平台或其它应用可向当前…
Browse files Browse the repository at this point in the history
…应用发送命令触发对应方法)
  • Loading branch information
nnhy committed Jan 1, 2025
1 parent 83094ec commit 1f89005
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Stardust.Extensions/StarFactoryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Net.Http;
using Microsoft.AspNetCore.Builder;
Expand All @@ -11,6 +12,7 @@
using NewLife.Configuration;
using NewLife.Log;
using NewLife.Reflection;
using NewLife.Remoting.Clients;
using Stardust;
using Stardust.Extensions;

Expand Down Expand Up @@ -44,6 +46,8 @@ public static StarFactory AddStardust(this IServiceCollection services, String?
services.AddSingleton(p => star.Tracer ?? DefaultTracer.Instance ?? (DefaultTracer.Instance ??= new DefaultTracer()));
//services.AddSingleton(p => star.Config);
services.AddSingleton(p => star.Service!);
services.AddSingleton(p => (star.Service as IEventProvider)!);
services.AddSingleton(p => (star.Service as ICommandClient)!);

// 替换为混合配置提供者,优先本地配置
//services.Replace(new ServiceDescriptor(typeof(IConfigProvider), p => star.Config, ServiceLifetime.Singleton));
Expand Down
2 changes: 2 additions & 0 deletions Stardust/StarFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public void Register(IObjectContainer container)
container.AddSingleton(this);
container.AddSingleton(p => Tracer ?? DefaultTracer.Instance ?? (DefaultTracer.Instance ??= new DefaultTracer()));
container.AddSingleton(p => Service!);
container.AddSingleton(p => (p.GetService<IRegistry>() as IEventProvider)!);
container.AddSingleton(p => (p.GetService<IRegistry>() as ICommandClient)!);

// 替换为混合配置提供者,优先本地配置
container.AddSingleton(p => GetConfig()!);
Expand Down

0 comments on commit 1f89005

Please sign in to comment.