private IHandlerRegistry GetHandlerRegistry(IDiContainerAdapter serviceProvider) => serviceProvider.GetService <IHandlerRegistry>( Configuration.HandlerRegistryType, exception => new PoezdConfigurationException( $"Can not get an instance of handler registry of type '{Configuration.HandlerRegistryType}'. " + "You should register this type in DI-container.", exception));
private IIngressApiMessageTypesRegistry GetMessageTypesRegistry(IDiContainerAdapter serviceProvider) => serviceProvider.GetService <IIngressApiMessageTypesRegistry>( Configuration.MessageTypesRegistryType, exception => new PoezdConfigurationException( $"Can not get an instance of message types registry of type '{Configuration.MessageTypesRegistryType}'. " + "You should register this type in DI-container.", exception));
private IPipeFitter GetIngressPipeFitter(IDiContainerAdapter serviceProvider) => serviceProvider.GetService <IPipeFitter>( Configuration.PipeFitterType, exception => new PoezdConfigurationException( $"Can not get an instance of ingress API pipe fitter of type '{Configuration.PipeFitterType.FullName}'." + "You should register this type in DI-container.", exception));
private IQueueNamePatternsProvider GetQueueNamePatternsProvider(IDiContainerAdapter serviceProvider) => serviceProvider.GetService <IQueueNamePatternsProvider>( Configuration.QueueNamePatternsProviderType, exception => new PoezdConfigurationException( $"Can not get an instance of queue name patterns provider of type '{Configuration.QueueNamePatternsProviderType}'. " + "You should register this type in DI-container.", exception));
private IPipeFitter GetExitPipeFitter(IDiContainerAdapter serviceProvider) => serviceProvider.GetService <IPipeFitter>( Configuration.ExitPipeFitterType, exception => new PoezdConfigurationException( $"Can not get instance of the message broker egress exit pipe fitter of type '{Configuration.ExitPipeFitterType.FullName}'. " + "You should register this type in DI-container.", exception));
/// <summary> /// Construct a new instance of message broker. /// </summary> /// <param name="messageBroker"> /// The message broker this ingress belongs to. /// </param> /// <param name="configuration"> /// The message broker configuration. /// </param> /// <param name="serviceProvider"> /// Service provider. /// </param> /// <exception cref="ArgumentNullException"> /// One of arguments is not specified. /// </exception> /// <exception cref="PoezdConfigurationException"> /// Can not get a required service from <paramref name="serviceProvider" />. /// </exception> public BrokerIngress( [NotNull] IMessageBroker messageBroker, [NotNull] BrokerIngressConfiguration configuration, [NotNull] IDiContainerAdapter serviceProvider) { _messageBroker = messageBroker ?? throw new ArgumentNullException(nameof(messageBroker)); Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); Driver = configuration.Driver ?? throw new ArgumentNullException($"{nameof(configuration)}.{nameof(configuration.Driver)}"); Apis = configuration.Apis.Select(api => new IngressApi(api, serviceProvider)).ToList().AsReadOnly(); _queueNameMatcher = (IQueueNameMatcher)serviceProvider.GetService(configuration.QueueNameMatcherType); EnterPipeFitter = GetEnterPipeFitter(); ExitPipeFitter = GetExitPipeFitter(); }