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(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddCorrelationId(); services.AddHttpContextAccessor(); services.AddMvc(); services.AddVersionedApiExplorer(options => options.GroupNameFormat = "'v'VVV"); services.AddApiVersioning(o => { o.ReportApiVersions = true; o.DefaultApiVersion = new ApiVersion(1, 0); o.AssumeDefaultVersionWhenUnspecified = true; }); services.AddOptions(); services.AddMemoryCache(); services.AddHttpClient(); services.AddSwagger(Configuration); services.AddDependencyInjection(Configuration); services.AddControllers(); services.AddHealthChecks(); services.AddApiAuthentication(Configuration); services.AddSwaggerGen(c => { // This coupled with the properties in the csproj allow the swagger page to show additional comments for methods var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); services.AddCors(); }
// Take in Lamar's ServiceRegistry instead of IServiceCollection (it implements IServiceCollection) public void ConfigureContainer(ServiceRegistry services) { _logger.LogDebug("ConfigureServices method entered."); //Https //services.AddHsts(x => x.IncludeSubDomains = true); //services.AddHttpsRedirection(options => //{ // //options.RedirectStatusCode = StatusCodes.Status301MovedPermanently; // //options.HttpsPort = 5001; //}); //Add framework services. var mvcBuilder = services.AddMvc(); mvcBuilder.AddMvcOptions(options => options.OutputFormatters.Add(new Microsoft.AspNetCore.Mvc.Formatters.XmlDataContractSerializerOutputFormatter(new System.Xml.XmlWriterSettings() { NamespaceHandling = System.Xml.NamespaceHandling.OmitDuplicates, Async = true, OmitXmlDeclaration = false }))); //TODO: configure removal of namespacing in the resulting xml mvcBuilder.AddMvcOptions(options => options.ReturnHttpNotAcceptable = true); mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); // required for certain features like [ApiController] //var jsonFormatter = mvcBuilder. services.AddAutoMapper(); // Swagger services.AddCustomSwagger(); // In memory cache services.AddMemoryCache(); // Resilience Policies: services.AddResiliencePolicies(); // Data Access: services.AddRavenDb(); //Versioning: services.AddApiVersioning(options => { options.ReportApiVersions = true; options.AssumeDefaultVersionWhenUnspecified = false; options.DefaultApiVersion = new ApiVersion(1, 0); options.ApiVersionReader = new UrlSegmentApiVersionReader(); options.ApiVersionSelector = new CurrentImplementationApiVersionSelector(options); }); //Messaging: services.AddAwsSns(); // Generic sorting/filtering/paging services.AddSortFilterPaging(); }