|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using System.Net.Sockets; |
5 | 3 | using System.Threading; |
6 | 4 | using AutoMapper; |
7 | | -using HwProj.EventBus.Client; |
8 | | -using HwProj.EventBus.Client.Implementations; |
9 | | -using HwProj.EventBus.Client.Interfaces; |
10 | 5 | using HwProj.Utils.Auth; |
11 | 6 | using HwProj.Utils.Configuration.Middleware; |
12 | 7 | using Microsoft.AspNetCore.Authentication.JwtBearer; |
13 | 8 | using Microsoft.AspNetCore.Builder; |
14 | 9 | using Microsoft.AspNetCore.Hosting; |
15 | 10 | using Microsoft.AspNetCore.Mvc; |
16 | 11 | using Microsoft.EntityFrameworkCore; |
17 | | -using Microsoft.Extensions.Configuration; |
18 | 12 | using Microsoft.Extensions.DependencyInjection; |
19 | 13 | using Microsoft.Extensions.Logging; |
20 | 14 | using Microsoft.IdentityModel.Tokens; |
21 | 15 | using Microsoft.OpenApi.Models; |
22 | 16 | using Newtonsoft.Json; |
23 | | -using Polly; |
24 | | -using RabbitMQ.Client; |
25 | | -using RabbitMQ.Client.Exceptions; |
26 | 17 |
|
27 | 18 | namespace HwProj.Utils.Configuration |
28 | 19 | { |
@@ -106,48 +97,6 @@ private static void ConfigureHwProjServiceSwaggerGen(this IServiceCollection ser |
106 | 97 | }); |
107 | 98 | } |
108 | 99 |
|
109 | | - public static IServiceCollection AddEventBus(this IServiceCollection services, IConfiguration configuration) |
110 | | - { |
111 | | - var eventBusSection = configuration.GetSection("EventBus"); |
112 | | - |
113 | | - var retryCount = 5; |
114 | | - if (!string.IsNullOrEmpty(eventBusSection["EventBusRetryCount"])) |
115 | | - { |
116 | | - retryCount = int.Parse(eventBusSection["EventBusRetryCount"]); |
117 | | - } |
118 | | - |
119 | | - services.AddSingleton(sp => Policy.Handle<SocketException>() |
120 | | - .Or<BrokerUnreachableException>() |
121 | | - .WaitAndRetry(retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))); |
122 | | - |
123 | | - services.AddSingleton<IConnectionFactory, ConnectionFactory>(sp => new ConnectionFactory |
124 | | - { |
125 | | - HostName = eventBusSection["EventBusHostName"], |
126 | | - UserName = eventBusSection["EventBusUserName"], |
127 | | - Password = eventBusSection["EventBusPassword"], |
128 | | - VirtualHost = eventBusSection["EventBusVirtualHost"] |
129 | | - }); |
130 | | - |
131 | | - services.AddSingleton<IDefaultConnection, DefaultConnection>(); |
132 | | - services.AddSingleton<IEventBus, EventBusRabbitMq>(); |
133 | | - |
134 | | - var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).ToList(); |
135 | | - var eventTypes = types.Where(x => typeof(Event).IsAssignableFrom(x)); |
136 | | - foreach (var eventType in eventTypes) |
137 | | - { |
138 | | - var fullTypeInterface = typeof(IEventHandler<>).MakeGenericType(eventType); |
139 | | - var handlersTypes = types.Where(x => |
140 | | - fullTypeInterface.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); |
141 | | - |
142 | | - foreach (var handlerType in handlersTypes) |
143 | | - { |
144 | | - services.AddTransient(handlerType); |
145 | | - } |
146 | | - } |
147 | | - |
148 | | - return services; |
149 | | - } |
150 | | - |
151 | 100 | public static IApplicationBuilder ConfigureHwProj(this IApplicationBuilder app, IHostingEnvironment env, |
152 | 101 | string serviceName, DbContext? context = null) |
153 | 102 | { |
|
0 commit comments