2016-11-21 12:41:36 +01:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2016-12-22 13:20:12 +01:00
|
|
|
|
using AspNetCore.Http;
|
2016-11-24 14:58:37 +01:00
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Extensions.DependencyInjection;
|
2017-05-16 09:23:35 +02:00
|
|
|
|
using global::Ordering.API.Application.IntegrationEvents;
|
2017-05-09 13:58:48 +02:00
|
|
|
|
using global::Ordering.API.Application.IntegrationEvents.Events;
|
2017-07-12 12:10:10 +02:00
|
|
|
|
using global::Ordering.API.Infrastructure.Filters;
|
2017-10-23 17:39:45 +02:00
|
|
|
|
using global::Ordering.API.Infrastructure.Middlewares;
|
2016-11-24 14:58:37 +01:00
|
|
|
|
using Infrastructure.AutofacModules;
|
|
|
|
|
using Infrastructure.Filters;
|
2016-12-22 13:20:12 +01:00
|
|
|
|
using Infrastructure.Services;
|
2017-10-13 11:35:26 +02:00
|
|
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
|
|
|
using Microsoft.ApplicationInsights.ServiceFabric;
|
2017-08-29 11:02:18 +02:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2017-05-24 15:32:22 +02:00
|
|
|
|
using Microsoft.Azure.ServiceBus;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2017-05-03 10:59:36 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
2017-03-31 10:30:56 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
2017-05-24 15:32:22 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
2017-03-31 10:30:56 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
|
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2017-03-23 19:10:55 +01:00
|
|
|
|
using Microsoft.Extensions.HealthChecks;
|
2017-08-23 00:10:28 +02:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2016-11-22 18:40:47 +01:00
|
|
|
|
using Ordering.Infrastructure;
|
2017-04-20 10:53:17 +02:00
|
|
|
|
using RabbitMQ.Client;
|
2017-07-12 12:10:10 +02:00
|
|
|
|
using Swashbuckle.AspNetCore.Swagger;
|
2016-11-24 14:58:37 +01:00
|
|
|
|
using System;
|
2017-07-12 12:10:10 +02:00
|
|
|
|
using System.Collections.Generic;
|
2017-03-31 10:30:56 +02:00
|
|
|
|
using System.Data.Common;
|
2017-08-29 18:11:30 +02:00
|
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
2016-11-22 18:40:47 +01:00
|
|
|
|
using System.Reflection;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2017-08-29 18:11:30 +02:00
|
|
|
|
public Startup(IConfiguration configuration)
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2017-08-29 18:11:30 +02:00
|
|
|
|
Configuration = configuration;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 18:11:30 +02:00
|
|
|
|
public IConfiguration Configuration { get; }
|
2016-09-06 17:09:19 -07:00
|
|
|
|
|
2016-11-24 14:58:37 +01:00
|
|
|
|
public IServiceProvider ConfigureServices(IServiceCollection services)
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2017-10-13 11:35:26 +02:00
|
|
|
|
RegisterAppInsights(services);
|
2017-10-11 18:53:26 +02:00
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
// Add framework services.
|
2016-12-07 13:57:31 +01:00
|
|
|
|
services.AddMvc(options =>
|
2016-11-24 14:58:37 +01:00
|
|
|
|
{
|
2017-07-13 13:42:29 +02:00
|
|
|
|
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
2017-02-26 12:22:38 -08:00
|
|
|
|
}).AddControllersAsServices(); //Injecting Controllers themselves thru DI
|
|
|
|
|
//For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
|
2017-08-26 22:55:24 +02:00
|
|
|
|
|
|
|
|
|
services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();
|
|
|
|
|
|
2017-03-23 19:10:55 +01:00
|
|
|
|
services.AddHealthChecks(checks =>
|
|
|
|
|
{
|
2017-05-09 13:54:45 +02:00
|
|
|
|
var minutes = 1;
|
|
|
|
|
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
|
|
|
|
|
{
|
|
|
|
|
minutes = minutesParsed;
|
|
|
|
|
}
|
|
|
|
|
checks.AddSqlCheck("OrderingDb", Configuration["ConnectionString"], TimeSpan.FromMinutes(minutes));
|
2017-03-23 19:10:55 +01:00
|
|
|
|
});
|
2017-07-13 13:42:29 +02:00
|
|
|
|
|
2016-11-22 18:40:47 +01:00
|
|
|
|
services.AddEntityFrameworkSqlServer()
|
2017-01-26 15:08:51 -08:00
|
|
|
|
.AddDbContext<OrderingContext>(options =>
|
|
|
|
|
{
|
2017-04-17 12:28:12 +02:00
|
|
|
|
options.UseSqlServer(Configuration["ConnectionString"],
|
|
|
|
|
sqlServerOptionsAction: sqlOptions =>
|
|
|
|
|
{
|
|
|
|
|
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
|
2017-10-10 19:56:34 -07:00
|
|
|
|
sqlOptions.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
|
2017-07-13 13:42:29 +02:00
|
|
|
|
});
|
|
|
|
|
},
|
2017-04-17 12:28:12 +02:00
|
|
|
|
ServiceLifetime.Scoped //Showing explicitly that the DbContext is shared across the HTTP request scope (graph of objects started in the HTTP request)
|
2017-01-26 15:08:51 -08:00
|
|
|
|
);
|
2016-11-22 18:40:47 +01:00
|
|
|
|
|
2017-09-13 14:53:06 +02:00
|
|
|
|
services.AddDbContext<IntegrationEventLogContext>(options =>
|
|
|
|
|
{
|
2017-10-10 19:56:34 -07:00
|
|
|
|
options.UseSqlServer(Configuration["ConnectionString"],
|
|
|
|
|
sqlServerOptionsAction: sqlOptions =>
|
|
|
|
|
{
|
|
|
|
|
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
|
|
|
|
|
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
|
|
|
|
|
sqlOptions.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
|
|
|
|
|
});
|
2017-09-13 14:53:06 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2017-06-20 12:54:32 -07:00
|
|
|
|
services.Configure<OrderingSettings>(Configuration);
|
|
|
|
|
|
2017-05-18 21:50:51 +03:00
|
|
|
|
services.AddSwaggerGen(options =>
|
2016-11-21 10:02:52 +01:00
|
|
|
|
{
|
2016-11-21 12:41:36 +01:00
|
|
|
|
options.DescribeAllEnumsAsStrings();
|
2017-05-23 16:39:22 +03:00
|
|
|
|
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
|
|
|
|
Title = "Ordering HTTP API",
|
|
|
|
|
Version = "v1",
|
|
|
|
|
Description = "The Ordering Service HTTP API",
|
2017-03-03 12:03:31 +01:00
|
|
|
|
TermsOfService = "Terms Of Service"
|
2016-11-21 12:41:36 +01:00
|
|
|
|
});
|
2017-07-12 12:10:10 +02:00
|
|
|
|
|
|
|
|
|
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
|
|
|
|
|
{
|
|
|
|
|
Type = "oauth2",
|
|
|
|
|
Flow = "implicit",
|
|
|
|
|
AuthorizationUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
|
|
|
|
|
TokenUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
|
|
|
|
|
Scopes = new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{ "orders", "Ordering API" }
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
options.OperationFilter<AuthorizeCheckOperationFilter>();
|
2016-11-21 10:02:52 +01:00
|
|
|
|
});
|
2016-09-12 20:28:55 -07:00
|
|
|
|
|
2016-12-12 10:15:24 +01:00
|
|
|
|
services.AddCors(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddPolicy("CorsPolicy",
|
|
|
|
|
builder => builder.AllowAnyOrigin()
|
|
|
|
|
.AllowAnyMethod()
|
|
|
|
|
.AllowAnyHeader()
|
|
|
|
|
.AllowCredentials());
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-22 13:20:12 +01:00
|
|
|
|
// Add application services.
|
|
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
2017-03-03 12:03:31 +01:00
|
|
|
|
services.AddTransient<IIdentityService, IdentityService>();
|
2017-03-31 10:30:56 +02:00
|
|
|
|
services.AddTransient<Func<DbConnection, IIntegrationEventLogService>>(
|
2017-07-13 13:42:29 +02:00
|
|
|
|
sp => (DbConnection c) => new IntegrationEventLogService(c));
|
|
|
|
|
|
2017-04-03 13:13:40 +02:00
|
|
|
|
services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();
|
2017-04-20 10:53:17 +02:00
|
|
|
|
|
2017-05-24 19:23:14 +02:00
|
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
|
2017-04-20 10:53:17 +02:00
|
|
|
|
{
|
2017-05-24 15:32:22 +02:00
|
|
|
|
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
|
|
|
|
|
{
|
|
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
|
|
|
|
|
|
2017-05-30 17:59:57 +02:00
|
|
|
|
var serviceBusConnectionString = Configuration["EventBusConnection"];
|
2017-05-24 19:23:14 +02:00
|
|
|
|
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
|
2017-04-20 10:53:17 +02:00
|
|
|
|
|
2017-05-24 18:59:29 +02:00
|
|
|
|
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
|
2017-05-24 15:32:22 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
2017-04-20 10:53:17 +02:00
|
|
|
|
{
|
2017-05-24 15:32:22 +02:00
|
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
2017-04-20 10:53:17 +02:00
|
|
|
|
|
2017-09-05 15:55:17 +02:00
|
|
|
|
|
2017-05-24 15:32:22 +02:00
|
|
|
|
var factory = new ConnectionFactory()
|
|
|
|
|
{
|
|
|
|
|
HostName = Configuration["EventBusConnection"]
|
|
|
|
|
};
|
2017-04-20 10:53:17 +02:00
|
|
|
|
|
2017-09-05 15:55:17 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusUserName"]))
|
|
|
|
|
{
|
|
|
|
|
factory.UserName = Configuration["EventBusUserName"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusPassword"]))
|
|
|
|
|
{
|
|
|
|
|
factory.Password = Configuration["EventBusPassword"];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 09:25:01 +01:00
|
|
|
|
var retryCount = 5;
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"]))
|
|
|
|
|
{
|
|
|
|
|
retryCount = int.Parse(Configuration["EventBusRetryCount"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount);
|
2017-05-24 15:32:22 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 01:35:44 +02:00
|
|
|
|
RegisterEventBus(services);
|
2017-08-29 11:02:18 +02:00
|
|
|
|
ConfigureAuthService(services);
|
2016-11-24 14:58:37 +01:00
|
|
|
|
services.AddOptions();
|
|
|
|
|
|
|
|
|
|
//configure autofac
|
|
|
|
|
|
|
|
|
|
var container = new ContainerBuilder();
|
|
|
|
|
container.Populate(services);
|
|
|
|
|
|
|
|
|
|
container.RegisterModule(new MediatorModule());
|
2017-03-03 12:03:31 +01:00
|
|
|
|
container.RegisterModule(new ApplicationModule(Configuration["ConnectionString"]));
|
2016-11-24 14:58:37 +01:00
|
|
|
|
|
|
|
|
|
return new AutofacServiceProvider(container.Build());
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 16:34:41 +02:00
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
|
|
|
{
|
|
|
|
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
|
|
|
|
loggerFactory.AddDebug();
|
2017-10-11 16:26:44 +02:00
|
|
|
|
loggerFactory.AddAzureWebAppDiagnostics();
|
|
|
|
|
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
2017-07-13 13:42:29 +02:00
|
|
|
|
|
2017-09-07 19:18:53 +02:00
|
|
|
|
var pathBase = Configuration["PATH_BASE"];
|
|
|
|
|
if (!string.IsNullOrEmpty(pathBase))
|
|
|
|
|
{
|
|
|
|
|
loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{pathBase}'");
|
|
|
|
|
app.UsePathBase(pathBase);
|
|
|
|
|
}
|
2017-10-11 16:26:44 +02:00
|
|
|
|
|
2016-12-12 10:15:24 +01:00
|
|
|
|
app.UseCors("CorsPolicy");
|
|
|
|
|
|
2017-03-06 16:06:32 +01:00
|
|
|
|
ConfigureAuth(app);
|
2016-12-07 13:57:31 +01:00
|
|
|
|
app.UseMvcWithDefaultRoute();
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
|
|
|
|
app.UseSwagger()
|
2017-05-18 21:50:51 +03:00
|
|
|
|
.UseSwaggerUI(c =>
|
|
|
|
|
{
|
2017-10-27 14:28:27 -07:00
|
|
|
|
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Ordering.API V1");
|
2017-07-12 12:10:10 +02:00
|
|
|
|
c.ConfigureOAuth2("orderingswaggerui", "", "", "Ordering Swagger UI");
|
2017-05-18 21:50:51 +03:00
|
|
|
|
});
|
2016-12-07 13:57:31 +01:00
|
|
|
|
|
2017-05-26 01:35:44 +02:00
|
|
|
|
ConfigureEventBus(app);
|
2017-05-17 00:40:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 11:35:26 +02:00
|
|
|
|
private void RegisterAppInsights(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddApplicationInsightsTelemetry(Configuration);
|
2017-10-16 16:10:40 +02:00
|
|
|
|
var orchestratorType = Configuration.GetValue<string>("OrchestratorType");
|
2017-10-23 17:39:45 +02:00
|
|
|
|
|
|
|
|
|
if (orchestratorType?.ToUpper() == "K8S")
|
2017-10-13 11:35:26 +02:00
|
|
|
|
{
|
|
|
|
|
// Enable K8s telemetry initializer
|
|
|
|
|
services.EnableKubernetes();
|
|
|
|
|
}
|
2017-10-23 17:39:45 +02:00
|
|
|
|
if (orchestratorType?.ToUpper() == "SF")
|
2017-10-13 11:35:26 +02:00
|
|
|
|
{
|
|
|
|
|
// Enable SF telemetry initializer
|
|
|
|
|
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
|
|
|
|
|
new FabricTelemetryInitializer());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 16:34:41 +02:00
|
|
|
|
private void ConfigureEventBus(IApplicationBuilder app)
|
|
|
|
|
{
|
2017-08-23 00:10:28 +02:00
|
|
|
|
var eventBus = app.ApplicationServices.GetRequiredService<BuildingBlocks.EventBus.Abstractions.IEventBus>();
|
2017-05-11 11:51:13 +02:00
|
|
|
|
|
2017-05-11 18:34:07 +02:00
|
|
|
|
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
|
2017-05-18 11:42:22 +02:00
|
|
|
|
eventBus.Subscribe<GracePeriodConfirmedIntegrationEvent, IIntegrationEventHandler<GracePeriodConfirmedIntegrationEvent>>();
|
2017-05-11 18:34:07 +02:00
|
|
|
|
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
|
2017-05-18 11:42:22 +02:00
|
|
|
|
eventBus.Subscribe<OrderStockRejectedIntegrationEvent, IIntegrationEventHandler<OrderStockRejectedIntegrationEvent>>();
|
2017-05-16 18:40:34 +02:00
|
|
|
|
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
|
|
|
|
|
eventBus.Subscribe<OrderPaymentSuccededIntegrationEvent, IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>>();
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
2017-03-06 16:06:32 +01:00
|
|
|
|
|
2017-08-29 11:02:18 +02:00
|
|
|
|
private void ConfigureAuthService(IServiceCollection services)
|
2017-03-06 16:06:32 +01:00
|
|
|
|
{
|
2017-08-29 18:11:30 +02:00
|
|
|
|
// prevent from mapping "sub" claim to nameidentifier.
|
|
|
|
|
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
|
|
|
|
|
|
2017-03-06 16:06:32 +01:00
|
|
|
|
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
2017-08-29 11:02:18 +02:00
|
|
|
|
|
|
|
|
|
services.AddAuthentication(options =>
|
|
|
|
|
{
|
|
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
|
|
|
|
|
}).AddJwtBearer(options =>
|
2017-03-06 16:06:32 +01:00
|
|
|
|
{
|
2017-08-29 11:02:18 +02:00
|
|
|
|
options.Authority = identityUrl;
|
|
|
|
|
options.RequireHttpsMetadata = false;
|
|
|
|
|
options.Audience = "orders";
|
2017-03-06 16:06:32 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
2017-06-01 14:32:22 +02:00
|
|
|
|
|
2017-08-29 11:02:18 +02:00
|
|
|
|
protected virtual void ConfigureAuth(IApplicationBuilder app)
|
|
|
|
|
{
|
2017-10-23 17:39:45 +02:00
|
|
|
|
if (Configuration.GetValue<bool>("UseLoadTest"))
|
|
|
|
|
{
|
|
|
|
|
app.UseMiddleware<ByPassAuthMiddleware>();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 11:02:18 +02:00
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 01:35:44 +02:00
|
|
|
|
private void RegisterEventBus(IServiceCollection services)
|
2017-05-24 15:32:22 +02:00
|
|
|
|
{
|
2017-11-10 17:37:18 +01:00
|
|
|
|
var subscriptionClientName = Configuration["SubscriptionClientName"];
|
|
|
|
|
|
2017-05-24 19:23:14 +02:00
|
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
|
2017-05-24 15:32:22 +02:00
|
|
|
|
{
|
2017-08-29 11:02:18 +02:00
|
|
|
|
services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
|
2017-05-24 15:32:22 +02:00
|
|
|
|
{
|
|
|
|
|
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
|
2017-06-26 18:05:02 +02:00
|
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
|
2017-05-24 15:32:22 +02:00
|
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
|
2017-11-10 17:37:18 +01:00
|
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
|
2017-05-24 15:32:22 +02:00
|
|
|
|
|
|
|
|
|
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
|
2017-06-26 18:05:02 +02:00
|
|
|
|
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
|
2017-05-24 15:32:22 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-10-12 09:25:01 +01:00
|
|
|
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>(sp =>
|
|
|
|
|
{
|
|
|
|
|
var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>();
|
|
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
|
|
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusRabbitMQ>>();
|
|
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
|
|
|
|
|
|
|
|
|
|
var retryCount = 5;
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"]))
|
|
|
|
|
{
|
|
|
|
|
retryCount = int.Parse(Configuration["EventBusRetryCount"]);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-10 17:37:18 +01:00
|
|
|
|
return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, subscriptionClientName, retryCount);
|
2017-10-12 09:25:01 +01:00
|
|
|
|
});
|
2017-05-24 15:32:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
|
|
|
|
}
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
}
|