public void ConfigureContainer(ServiceRegistry services) { services.UseNextPipeDefaultConfiguration(Configuration); services.AddControllers(); services.IncludeRegistry <LamarRegistry>(); services.AddMvc().AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); // in-comment this again to get complete IOC validation //var container = new Container(services); //container.AssertConfigurationIsValid(); services.AddHostedService <ArchiveManagerService>(); services.AddHostedService <ModuleStateManagerService>(); services.AddHostedService <ResourceAndStateManagerService>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "NextPipe Beta Core API", Version = "v1" }); }); }
public void ConfigureContainer(ServiceRegistry services) { services.AddOptions(); services.Configure <KafkaOptions>(Configuration.GetSection("Kafka")); services.AddControllers(); services.AddMvc() .AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddLogging(); services.AddRouting(option => { option.LowercaseUrls = true; }); services.For <IMediator>().Use <Mediator>().Transient(); services.For <ServiceFactory>().Use(ctx => ctx.GetInstance); services.AddCors(options => { options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); }); //Kafka services.For(typeof(IKafkaPublisher <>)).Add(typeof(KafkaPublisher <>)).Scoped(); services.AddHostedService <BaselineListener>(); services.AddTransient <IUserInput, UserInput>(); services.AddTransient <ITradeAlgorithm, TradeAgorithm>(); services.AddMemoryCache(); }
public void ConfigureContainer(ServiceRegistry services) { const string variable = "OPEN_WEATHER_MAP_API_KEY"; if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(variable))) { Environment.SetEnvironmentVariable(variable, "fc28830c17565772df3697a3b91bcd47"); } // It's a good practice to avoid registering the infrastructure layer with the upper layers. // This can be done using the method below. // https://ardalis.com/avoid-referencing-infrastructure-in-visual-studio-solutions // //const string name = "Way2.Infrastructure.DependencyResolution.dll"; //var path = Path.Combine(AppContext.BaseDirectory, name); //var assembly = Assembly.LoadFrom(path); //services.Scan(_ => //{ // _.Assembly(assembly); // _.LookForRegistries(); //}); services.AddLamar <InfrastructureRegistry>(); services.AddControllers(); services.AddHealthChecks(); services.AddApiVersioning(); services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "API v1", Version = "v1" }); options.OperationFilter <RemoveVersionFromParameter>(); options.DocumentFilter <ReplaceVersionWithExactValueInPath>(); }); services.AddHostedService <DatabaseMigrationHostedService>(); services.AddHostedService <DatabaseSeedHostedService>(); services.AddHostedService <WeatherFetcherBackgroundService>(); }
public void ConfigureContainer(ServiceRegistry services) { services.AddOptions(); services.Configure <KafkaOptions>(Configuration.GetSection("Kafka")); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Order APIs", Version = "v1" }); }); services.AddEntityFrameworkSqlServer() .AddDbContext <PaymentDBContext>(options => { options.UseSqlServer(Configuration["ConnectionString"], sqlServerOptionsAction: sqlOptions => { sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); sqlOptions.EnableRetryOnFailure(maxRetryCount: 3, maxRetryDelay: TimeSpan.FromSeconds(1), errorNumbersToAdd: null); }); }); services.For <IMediator>().Use <Mediator>().Transient(); services.For <ServiceFactory>().Use(ctx => ctx.GetInstance); services.Scan(scanner => { scanner.AssemblyContainingType <CreatePaymentCommand>(); scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler <,>)); }); services.AddMvc() .AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddControllers(); services.AddSingleton <PublishPaymentResponseService>(); services.AddScoped <IPaymentRepository, PaymentRepository>(); services.For(typeof(IKafkaProducer <>)).Add(typeof(KafkaProducer <>)).Singleton(); services.For(typeof(IKafkaSubscriber <>)).Add(typeof(KafkaSubscriber <>)).Singleton(); services.For(typeof(IKafkaMessageService <,>)).Add(typeof(KafkaMessageService <,>)).Singleton(); services.AddHostedService <PaymentBackgroundAvroService>(); services.AddHostedService <PaymentBackgroundJsonService>(); services.AddCors(options => { options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddCors(options => { options.AddPolicy(name: AllowDevCors, builder => { builder.WithOrigins("http://localhost:3000"); }); }); services.AddControllersWithViews(); services.IncludeRegistry <WebRegistry>(); services.AddHostedService <RabbitService>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ConsumerModul.GitLab - NextPipe Module - Beta API", Version = "v1" }); }); services.AddSpaStaticFiles(conf => { conf.RootPath = "ClientApp/build"; }); }
public static async Task Main(string[] args) { try { var builder = new HostBuilder() .UseLamar() .ConfigureServices((context, services) => { var registry = new ServiceRegistry(); registry.Scan(s => { s.TheCallingAssembly(); s.WithDefaultConventions(); }); registry.Configure <ProbeConfig>(option => { int.TryParse(Environment.GetEnvironmentVariable("LivenessSignalIntervalSeconds"), out int interval); option.LivenessSignalIntervalSeconds = interval; option.StartupFilePath = Environment.GetEnvironmentVariable("StartupFilePath"); option.LivenessFilePath = Environment.GetEnvironmentVariable("LivenessFilePath"); }); registry.Configure <AppConfig>(option => { option.SubscriptionId = Environment.GetEnvironmentVariable("SubscriptionId"); option.TenantId = Environment.GetEnvironmentVariable("TenantId"); option.ClientId = Environment.GetEnvironmentVariable("ClientId"); option.ClientSecret = Environment.GetEnvironmentVariable("ClientSecret"); option.ResourceGroupName = Environment.GetEnvironmentVariable("ResourceGroupName"); option.ServiceBusNamespace = Environment.GetEnvironmentVariable("ServiceBusNamespace"); option.ServiceBusNamespaceSASKey = Environment.GetEnvironmentVariable("ServiceBusNamespaceSASKey"); option.RequestQueueName = Environment.GetEnvironmentVariable("RequestQueueName"); option.ResponseQueueName = Environment.GetEnvironmentVariable("ResponseQueueName"); var config = new NLog.Config.LoggingConfiguration(); // Targets where to log to: File & Console var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "service.log" }; var logconsole = new NLog.Targets.ConsoleTarget("logconsole"); // Rules for mapping loggers to targets config.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, logconsole); config.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, logfile); // Apply config LogManager.Configuration = config; }); var qConfig = new Container(registry).GetInstance <IOptions <AppConfig> >().Value; registry.For <IStartupActivity>() .Use <QueueProbe>() .Ctor <string>("queueName").Is(qConfig.RequestQueueName) .Named(qConfig.RequestQueueName); registry.For <IStartupActivity>() .Use <QueueProbe>() .Ctor <string>("queueName").Is(qConfig.ResponseQueueName) .Named(qConfig.ResponseQueueName); //registry.For<IHostedService>().Use<BackgroundServiceWrapper>(); registry.AddHostedService <BackgroundServiceWrapper>(); services.AddLamar(registry); }) .ConfigureLogging(logging => { logging.ClearProviders(); }) .UseNLog(); // Build and run the host in one go; .RCA is specialized for running it in a console. // It registers SIGTERM(Ctrl-C) to the CancellationTokenSource that's shared with all services in the container. await builder.Build().RunAsync().ConfigureAwait(false); LogManager.GetCurrentClassLogger().Info("The host container has terminated. Press ANY key to exit the console."); } catch (Exception ex) { // NLog: catch setup errors (exceptions thrown inside of any containers may not necessarily be caught) LogManager.GetCurrentClassLogger().Fatal(ex, "Something went wrong. Application will exit cleanly."); throw; } finally { // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) LogManager.Shutdown(); } }