/// <summary> /// 插件载入,作为第零步 /// </summary> public static void LoadAddIn() { addInImporter = new AddInImporter(); addInImporter.LoadAddIn(Logger); addInImporter.AutoRegist(Logger); DependencyHelper.Flush(); }
public void Setup() { DependencyHelper.ServiceCollection.AddMessageMvcRedis(); DependencyHelper.ServiceCollection.AddMessageMvcKafka(); DependencyHelper.Flush(); DependencyHelper.ServiceCollection.UseTest(typeof(ApiContraceJsonTest).Assembly); }
/// <summary> /// 检查并注入配置 /// </summary> internal static void AddDependency(IServiceCollection services) { ZeroFlowControl.LoadAddIn(); //IZeroContext构造 services.AddSingleton <IZeroOption>(pri => MessagePostOption.Instance); services.TryAddTransient <IUser, UserInfo>(); services.TryAddTransient <IZeroContext, ZeroContext>(); //消息发送 services.AddTransient <IFlowMiddleware, MessagePoster>(); //API路由与执行 services.AddTransient <IMessageMiddleware, ApiExecuter>(); //消息格式 services.AddTransient <IInlineMessage, InlineMessage>(); services.AddTransient <IMessageResult, MessageResult>(); //序列化工具 if (ZeroAppOption.Instance.UsMsJson) { services.TryAddTransient <ISerializeProxy, JsonSerializeProxy>(); services.TryAddTransient <IJsonSerializeProxy, JsonSerializeProxy>(); services.TryAddTransient <IXmlSerializeProxy, XmlSerializeProxy>(); } else { services.TryAddTransient <ISerializeProxy, NewtonJsonSerializeProxy>(); services.TryAddTransient <IJsonSerializeProxy, NewtonJsonSerializeProxy>(); services.TryAddTransient <IXmlSerializeProxy, XmlSerializeProxy>(); } DependencyHelper.Flush(); }
public void SetUp() { if (poster != null) { return; } poster = new HttpPoster(); HttpApp.AddMessageMvcHttpClient(DependencyHelper.ServiceCollection); DependencyHelper.Flush(); }
/// <summary> /// 配置校验,作为第一步 /// </summary> public static async Task CheckConfig() { if (ZeroAppOption.Instance.ApplicationState >= StationState.Check) { return; } Logger.Information("【配置校验】开始"); ZeroAppOption.Instance.SetApplicationState(StationState.Check); var checkers = DependencyHelper.RootProvider.GetServices <IAppChecker>(); foreach (var checker in checkers) { try { await checker.Check(ZeroAppOption.Instance); } catch (Exception ex) { Logger.Exception(ex, "ZeroFlowControl.Check:{0}", checker.GetTypeName()); throw; } } foreach (var checker in DependencyHelper.RootProvider.GetServices <IFlowMiddleware>().OfType <IAppChecker>()) { try { await checker.Check(ZeroAppOption.Instance); } catch (Exception ex) { Logger.Exception(ex, "ZeroFlowControl.Check:{0}", checker.GetTypeName()); throw; } } configChecker.CheckLast(ZeroAppOption.Instance, Logger); var options = DependencyHelper.RootProvider.GetServices <IZeroOption>(); foreach (var option in options) { option.Load(true); Logger.Debug(() => $"〖{option.OptionName}〗{(option.IsDynamic ? "动态更新":"静态配置")},{option.SupperUrl}\n{option.ToJson(true)}"); } addInImporter.LateConfigRegist(Logger); ConfigurationHelper.IsLocked = true; DependencyHelper.Flush(); Middlewares = DependencyHelper.RootProvider.GetServices <IFlowMiddleware>().OrderBy(p => p.Level).ToArray(); Logger.Information("【配置校验】完成"); }
/// <summary> /// 发现 /// </summary> static async Task DiscoverAll() { Logger.Information("【发现】开始"); var discovers = DependencyHelper.RootProvider.GetServices <IZeroDiscover>(); foreach (var discover in discovers) { try { await discover.Discovery(); } catch (Exception e) { Logger.Exception(e, "[发现] {0}"); } } Middlewares = DependencyHelper.RootProvider.GetServices <IFlowMiddleware>().OrderBy(p => p.Level).ToArray(); foreach (var mid in Middlewares) { try { Logger.Information("[发现] {0}", mid.Name); await mid.Discovery(); } catch (Exception e) { Logger.Exception(e, "[发现] {0}", mid.Name); } } var servcies = DependencyHelper.RootProvider.GetServices <IService>(); if (servcies != null) { foreach (var service in servcies) { Services.TryAdd(service.ServiceName, service); Logger.Information($"【服务自注册】{service.ServiceName}"); } } DependencyHelper.Flush(); Logger.Information("【发现】完成"); }