/// <summary> /// 构造函数 /// </summary> /// <param name="config">NodeServer配置</param> public DefaultNodeServer(NodeServerConfig config) { ValidateConfig(config); logger = LoggerManager.ServerLoggerFactory.CreateLogger <DefaultNodeServer>(); server = config.Communication; protocolStackFactory = config.ProtocolStackFactory; serviceProvider = config.ServiceProvider; RouteManager = config.RouteFactory.CreateRouteManager(); routeDescriptor = config.RouteFactory.CreateRouteDescriptor(); if (config.ServiceConfigs != null) { routeDescriptor.SetServiceConfig(config.ServiceConfigs); } serializer = config.Serializer; serviceInvoker = config.ServiceInvoker; serviceProcessor = config.ServiceProcessor; loginValidator = config.LoginValidator; this.config = config ?? throw new InvalidOperationException("Argument config is null."); }
/// <summary> /// 验证配置对象 /// </summary> /// <param name="config"></param> private void ValidateConfig(NodeServerConfig config) { if (config.ServiceProvider == null) { throw new InvalidOperationException("ServiceProvider config is null."); } if (config.RouteFactory == null) { throw new InvalidOperationException("RouteFactory config is null."); } if (config.Serializer == null) { throw new InvalidOperationException("Serializer config is null."); } if (config.ServiceInvoker == null) { throw new InvalidOperationException("ServiceInvoker config is null."); } if (config.LoginValidator == null) { throw new InvalidOperationException("LoginValidator config is null."); } }