/// <summary> /// Load the specified config. /// </summary> /// <param name="config">The config.</param> private void LoadConfig(RpcConfigurationConfig config) { // channel m_ChannelActivators.Clear(); m_ServerPortActivators.Clear(); foreach (var channelConfig in RpcConfigurationUtility.EnumerateAll(config.Channels)) { if (string.IsNullOrEmpty(channelConfig.Name)) { throw new RpcConfigurationException("The channel name is not set."); } m_ChannelActivators.Add(RpcConfigurationUtility.NormalizeName(channelConfig.Name), new Factory <Channel>(() => CreateChannel(channelConfig, this), DisposeChannel)); m_ServerPortActivators.Add(RpcConfigurationUtility.NormalizeName(channelConfig.Name), new Factory <ServerPort>(() => CreateServerPort(channelConfig, this), DisposeServerPort)); } // credential m_ChannelCredentialsActivators.Clear(); m_ServerCredentialsActivators.Clear(); foreach (var credentialsConfig in RpcConfigurationUtility.EnumerateAll(config.Credentials, config.ExtraCredentials)) { if (string.IsNullOrEmpty(credentialsConfig.Name)) { throw new RpcConfigurationException("The credential name is not set."); } m_ChannelCredentialsActivators.Add(RpcConfigurationUtility.NormalizeName(credentialsConfig.Name), new Factory <ChannelCredentials>(() => CreateChannelCredentials(credentialsConfig, this), null)); m_ServerCredentialsActivators.Add(RpcConfigurationUtility.NormalizeName(credentialsConfig.Name), new Factory <ServerCredentials>(() => CreateServerCredentials(credentialsConfig, this), null)); } // interceptor m_InterceptorActivators.Clear(); foreach (var interceptorConfig in RpcConfigurationUtility.EnumerateAll(config.Interceptors, config.ExtraInterceptors)) { if (interceptorConfig is Interceptors.InterceptorReference) { continue; } if (string.IsNullOrEmpty(interceptorConfig.Name)) { throw new RpcConfigurationException("The interceptor name is not set."); } m_InterceptorActivators.Add(RpcConfigurationUtility.NormalizeName(interceptorConfig.Name), new Factory <Interceptor>(() => CreateInterceptor(interceptorConfig, this), DisposeInterceptor)); } // callInvoker m_CallInvokerActivators.Clear(); foreach (var invokerConfig in RpcConfigurationUtility.EnumerateAll(config.CallInvokers, config.ExtraCallInvokers)) { if (string.IsNullOrEmpty(invokerConfig.Name)) { throw new RpcConfigurationException("The callInvoker name is not set."); } m_CallInvokerActivators.Add(RpcConfigurationUtility.NormalizeName(invokerConfig.Name), new Factory <CallInvoker>(() => CreateCallInvoker(invokerConfig, this), DisposeCallInvoker)); } // service m_ServiceConfigs.Clear(); foreach (var serviceConfig in RpcConfigurationUtility.EnumerateAll(config.Services)) { if (string.IsNullOrEmpty(serviceConfig.Name)) { throw new RpcConfigurationException("The service name is not set."); } m_ServiceConfigs.Add(RpcConfigurationUtility.NormalizeName(serviceConfig.Name), serviceConfig); } }
/// <summary> /// Create a new instance. /// </summary> /// <param name="config">The config.</param> /// <param name="disposableRpcObjects">A value indicating whether the generated gRPC objects can be disposed.</param> public RpcConfigurationContext(RpcConfigurationConfig config, bool disposableRpcObjects = false) { DisposableRpcObjects = disposableRpcObjects; LoadConfig(config); }