// 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.AddHttpClient(); services.AddSwagger(Configuration); services.AddDependencyInjection(Configuration); services.AddControllers(); services.AddHealthChecks(); 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); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddDefaultCorrelationId(); 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.AddHttpClient(string.Empty) .AddCorrelationIdForwarding(); services.AddSwagger(); services.AddHealthChecks().AddCheck <ReadinessCheck>("PROJECT_NAME readiness", tags: new[] { "readiness" }); services.AddCustomizedLogging(); services.AddDependencyInjection(Configuration); services.AddHealthChecks(); services.AddControllers() .AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())); }
// 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(); }
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>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new ExploreMetricConverter())); services.AddApiVersioning(); const string ConfigSection = "Explorer"; services.Configure <ExplorerOptions>(Configuration.GetSection(ConfigSection)); services.Configure <ConnectionOptions>(Configuration.GetSection(ConfigSection)); services.AddAircloakJsonApiServices <ExplorerApiAuthProvider>(); // Enriched event logger for sentry services.AddScoped <ISentryEventProcessor, ExplorerEventProcessor>(); // Singleton services services .AddSingleton <ExplorationRegistry>(); // Scoped services services .AddScoped <MetricsPublisher, SimpleMetricsPublisher>(); // Transient Services services .AddTransient <ExplorationScopeBuilder, TypeBasedScopeBuilder>(); // Register Explorer Components services.IncludeRegistry <ComponentRegistry>(); if (Environment.IsDevelopment()) { services.AddCors(options => options.AddDefaultPolicy(b => b.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())); } }