public Startup(IConfiguration configuration) { AWSXRayRecorder.InitializeInstance(configuration); AWSXRayRecorder.RegisterLogger(Amazon.LoggingOptions.Console); AWSSDKHandler.RegisterXRayForAllServices(); Configuration = configuration; }
static Startup() // create log4j instance { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); log = LogManager.GetLogger(typeof(Startup)); AWSXRayRecorder.RegisterLogger(LoggingOptions.Log4Net); }
public HomeController(ILogger <HomeController> logger, IConfiguration configuration) { AWSXRayRecorder.RegisterLogger(LoggingOptions.Console); _configuration = configuration; AWSSDKHandler.RegisterXRayForAllServices(); _httpClient = new HttpClient(new HttpClientXRayTracingHandler(new HttpClientHandler())); _logger = logger; _variety.PetTypes = new List <SelectListItem>() { new SelectListItem() { Value = "all", Text = "All" }, new SelectListItem() { Value = "puppy", Text = "Puppy" }, new SelectListItem() { Value = "kitten", Text = "Kitten" }, new SelectListItem() { Value = "bunny", Text = "Bunny" } }; _variety.PetColors = new List <SelectListItem>() { new SelectListItem() { Value = "all", Text = "All" }, new SelectListItem() { Value = "brown", Text = "Brown" }, new SelectListItem() { Value = "black", Text = "Black" }, new SelectListItem() { Value = "white", Text = "White" } }; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); services .AddMvc() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddFluentValidation(Assembly.GetAssembly(typeof(CreatePersonRequestObjectValidator))); services.AddApiVersioning(o => { o.DefaultApiVersion = new ApiVersion(1, 0); o.AssumeDefaultVersionWhenUnspecified = true; // assume that the caller wants the default version if they don't specify o.ApiVersionReader = new UrlSegmentApiVersionReader(); // read the version number from the url segment header) }); services.AddSingleton <IApiVersionDescriptionProvider, DefaultApiVersionDescriptionProvider>(); services.AddHttpContextAccessor(); services.AddDynamoDbHealthCheck <PersonDbEntity>(); services.AddSwaggerGen(c => { c.AddSecurityDefinition("Token", new OpenApiSecurityScheme { In = ParameterLocation.Header, Description = "Your Hackney API Key", Name = "X-Api-Key", Type = SecuritySchemeType.ApiKey }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Token" } }, new List <string>() } }); //Looks at the APIVersionAttribute [ApiVersion("x")] on controllers and decides whether or not //to include it in that version of the swagger document //Controllers must have this [ApiVersion("x")] to be included in swagger documentation!! c.DocInclusionPredicate((docName, apiDesc) => { apiDesc.TryGetMethodInfo(out var methodInfo); var versions = methodInfo? .DeclaringType?.GetCustomAttributes() .OfType <ApiVersionAttribute>() .SelectMany(attr => attr.Versions).ToList(); return(versions?.Any(v => $"{v.GetFormattedApiVersion()}" == docName) ?? false); }); //Get every ApiVersion attribute specified and create swagger docs for them foreach (var apiVersion in _apiVersions) { var version = $"v{apiVersion.ApiVersion.ToString()}"; c.SwaggerDoc(version, new OpenApiInfo { Title = $"{ApiName}-api {version}", Version = version, Description = $"{ApiName} version {version}. Please check older versions for depreciated endpoints." }); } c.CustomSchemaIds(x => x.FullName); // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } }); services.ConfigureLambdaLogging(Configuration); AWSXRayRecorder.InitializeInstance(Configuration); AWSXRayRecorder.RegisterLogger(LoggingOptions.SystemDiagnostics); services.AddLogCallAspect(); services.ConfigureDynamoDB(); services.ConfigureSns(); services.AddSnsGateway(); services.AddTokenFactory(); services.AddHttpContextWrapper(); RegisterGateways(services); RegisterUseCases(services); services.AddSingleton <IConfiguration>(Configuration); }