delete startup.cs
This commit is contained in:
		
							parent
							
								
									433419b583
								
							
						
					
					
						commit
						212343f274
					
				| @ -1,176 +0,0 @@ | ||||
| namespace Microsoft.eShopOnContainers.Payment.API; | ||||
| 
 | ||||
| public class Startup | ||||
| { | ||||
|     public Startup(IConfiguration configuration) | ||||
|     { | ||||
|         Configuration = configuration; | ||||
|     } | ||||
| 
 | ||||
|     public IConfiguration Configuration { get; } | ||||
| 
 | ||||
|     // This method gets called by the runtime. Use this method to add services to the container. | ||||
|     public IServiceProvider ConfigureServices(IServiceCollection services) | ||||
|     { | ||||
|         services.AddCustomHealthCheck(Configuration); | ||||
|         services.Configure<PaymentSettings>(Configuration); | ||||
| 
 | ||||
|         RegisterAppInsights(services); | ||||
| 
 | ||||
|         if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) | ||||
|         { | ||||
|             services.AddSingleton<IServiceBusPersisterConnection>(sp => | ||||
|             { | ||||
|                 var serviceBusConnectionString = Configuration["EventBusConnection"]; | ||||
|                 var subscriptionClientName = Configuration["SubscriptionClientName"]; | ||||
| 
 | ||||
|                 return new DefaultServiceBusPersisterConnection(serviceBusConnectionString); | ||||
|             }); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             services.AddSingleton<IRabbitMQPersistentConnection>(sp => | ||||
|             { | ||||
|                 var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>(); | ||||
|                 var factory = new ConnectionFactory() | ||||
|                 { | ||||
|                     HostName = Configuration["EventBusConnection"], | ||||
|                     DispatchConsumersAsync = true | ||||
|                 }; | ||||
| 
 | ||||
|                 if (!string.IsNullOrEmpty(Configuration["EventBusUserName"])) | ||||
|                 { | ||||
|                     factory.UserName = Configuration["EventBusUserName"]; | ||||
|                 } | ||||
| 
 | ||||
|                 if (!string.IsNullOrEmpty(Configuration["EventBusPassword"])) | ||||
|                 { | ||||
|                     factory.Password = Configuration["EventBusPassword"]; | ||||
|                 } | ||||
| 
 | ||||
|                 var retryCount = 5; | ||||
|                 if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) | ||||
|                 { | ||||
|                     retryCount = int.Parse(Configuration["EventBusRetryCount"]); | ||||
|                 } | ||||
| 
 | ||||
|                 return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         RegisterEventBus(services); | ||||
| 
 | ||||
|         var container = new ContainerBuilder(); | ||||
|         container.Populate(services); | ||||
|         return new AutofacServiceProvider(container.Build()); | ||||
|     } | ||||
| 
 | ||||
|     // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||||
|     public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) | ||||
|     { | ||||
|         //loggerFactory.AddAzureWebAppDiagnostics(); | ||||
|         //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); | ||||
| 
 | ||||
|         var pathBase = Configuration["PATH_BASE"]; | ||||
|         if (!string.IsNullOrEmpty(pathBase)) | ||||
|         { | ||||
|             app.UsePathBase(pathBase); | ||||
|         } | ||||
| 
 | ||||
|         ConfigureEventBus(app); | ||||
| 
 | ||||
|         app.UseRouting(); | ||||
|         app.UseEndpoints(endpoints => | ||||
|         { | ||||
|             endpoints.MapHealthChecks("/hc", new HealthCheckOptions() | ||||
|             { | ||||
|                 Predicate = _ => true, | ||||
|                 ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse | ||||
|             }); | ||||
|             endpoints.MapHealthChecks("/liveness", new HealthCheckOptions | ||||
|             { | ||||
|                 Predicate = r => r.Name.Contains("self") | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     private void RegisterAppInsights(IServiceCollection services) | ||||
|     { | ||||
|         services.AddApplicationInsightsTelemetry(Configuration); | ||||
|         services.AddApplicationInsightsKubernetesEnricher(); | ||||
|     } | ||||
| 
 | ||||
|     private void RegisterEventBus(IServiceCollection services) | ||||
|     { | ||||
|         if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) | ||||
|         { | ||||
|             services.AddSingleton<IEventBus, EventBusServiceBus>(sp => | ||||
|             { | ||||
|                 var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); | ||||
|                 var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); | ||||
|                 var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); | ||||
|                 string subscriptionName = Configuration["SubscriptionClientName"]; | ||||
| 
 | ||||
|                 return new EventBusServiceBus(serviceBusPersisterConnection, logger, | ||||
|                     eventBusSubcriptionsManager, sp, subscriptionName); | ||||
|             }); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             services.AddSingleton<IEventBus, EventBusRabbitMQ>(sp => | ||||
|             { | ||||
|                 var subscriptionClientName = Configuration["SubscriptionClientName"]; | ||||
|                 var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>(); | ||||
|                 var logger = sp.GetRequiredService<ILogger<EventBusRabbitMQ>>(); | ||||
|                 var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); | ||||
| 
 | ||||
|                 var retryCount = 5; | ||||
|                 if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) | ||||
|                 { | ||||
|                     retryCount = int.Parse(Configuration["EventBusRetryCount"]); | ||||
|                 } | ||||
| 
 | ||||
|                 return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, sp, eventBusSubcriptionsManager, subscriptionClientName, retryCount); | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         services.AddTransient<OrderStatusChangedToStockConfirmedIntegrationEventHandler>(); | ||||
|         services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); | ||||
|     } | ||||
| 
 | ||||
|     private void ConfigureEventBus(IApplicationBuilder app) | ||||
|     { | ||||
|         var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>(); | ||||
|         eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent, OrderStatusChangedToStockConfirmedIntegrationEventHandler>(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| public static class CustomExtensionMethods | ||||
| { | ||||
|     public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) | ||||
|     { | ||||
|         var hcBuilder = services.AddHealthChecks(); | ||||
| 
 | ||||
|         hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); | ||||
| 
 | ||||
|         if (configuration.GetValue<bool>("AzureServiceBusEnabled")) | ||||
|         { | ||||
|             hcBuilder | ||||
|                 .AddAzureServiceBusTopic( | ||||
|                     configuration["EventBusConnection"], | ||||
|                     topicName: "eshop_event_bus", | ||||
|                     name: "payment-servicebus-check", | ||||
|                     tags: new string[] { "servicebus" }); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             hcBuilder | ||||
|                 .AddRabbitMQ( | ||||
|                     $"amqp://{configuration["EventBusConnection"]}", | ||||
|                     name: "payment-rabbitmqbus-check", | ||||
|                     tags: new string[] { "rabbitmqbus" }); | ||||
|         } | ||||
| 
 | ||||
|         return services; | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user