Пример #1
0
        public static IServiceCollection AddBuskConsumer(this IServiceCollection services, Action <DispatcherBuilder> configure)
        {
            var builder = new DispatcherBuilder();

            configure?.Invoke(builder);
            services.AddBuskConsumer(builder);
            return(services);
        }
Пример #2
0
        internal static IServiceCollection AddBuskSubscriptions(this IServiceCollection services, DispatcherBuilder builder)
        {
            var request = new Dto.CreateSubscription()
            {
                Endpoint = Url.Combine(builder.Consumer, Magic.VirtualPath.Consume),
                Topics   = builder.GetTopics()
            };

            using (var httpClientHandler = new HttpClientHandler()
            {
                ClientCertificateOptions = ClientCertificateOption.Manual,
                ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true
            })
            {
                var uri = Url.Combine(builder.Endpoint, Magic.VirtualPath.Subscription);
                using (var httpClient = new HttpClient(httpClientHandler))
                {
                    var response = httpClient.PostAsJsonAsync(uri, request).GetAwaiter().GetResult();
                    response.EnsureSuccessStatusCode();
                }
            }
            return(services);
        }
Пример #3
0
 internal static IServiceCollection AddBuskHandlers(this IServiceCollection services, DispatcherBuilder builder)
 {
     foreach (var handlerType in builder.GetHandlerTypes())
     {
         services.AddTransient(handlerType);
     }
     return(services);
 }
Пример #4
0
        public static IServiceCollection AddBuskConsumer(this IServiceCollection services, DispatcherBuilder builder)
        {
            services.AddSingleton <IDispatcher>(serviceProvider => builder.Create(serviceProvider));

            // Register Handlers (if enabled) //
            if (builder.IsRegisterHandlers)
            {
                services.AddBuskHandlers(builder);
            }

            // Create Subscriptions (if enabled) //
            if (builder.IsCreateSubscriptions)
            {
                services.AddBuskSubscriptions(builder);
            }

            return(services);
        }