using Microsoft.Extensions.DependencyInjection; try { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("Serilog.json") .AddJsonFile($"Serilog.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true) .Build(); var MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; var builder = WebApplication.CreateBuilder(args); var logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .WriteTo.Exceptionless(builder.Configuration.GetValue("Exceptionless:ApiKey"), builder.Configuration.GetValue("Exceptionless:ServerUrl"), new string[] { "hg-internal-webapi" }) .CreateLogger(); Log.Logger = logger; builder.Services.AddLogging(logging => { logging.ClearProviders(); logging.AddSerilog(logger); }); // Add services to the container. builder.Services.AddDGEntityFramework(options => { options.UseOracle(builder.Configuration.GetConnectionString("hgcrm"), p => p.UseOracleSQLCompatibility("11")); }); // Add services to the container. builder.Services.AddDGEntityFramework(options => { options.UseOracle(builder.Configuration.GetConnectionString("crm_hg_internal"), p => p.UseOracleSQLCompatibility("11")); }); builder.Services.AddRedis(builder.Configuration); builder.Services .AddAutoIoc(typeof(IScopedDependency), LifeCycle.Scoped) .AddAutoIoc(typeof(ISingletonDependency), LifeCycle.Singleton) .AddAutoIoc(typeof(ITransientDependency), LifeCycle.Transient) .AddMapper(); builder.Services.AddCors(option => { option.AddPolicy(MyAllowSpecificOrigins, policy => { policy.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); builder.Services.AddControllers() .AddApiResult() .AddApiSignature() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonOptionsExtensions()); }); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Version = "v1", Title = "HG CORE INTERNAL API", Description = "HG CORE INTERNAL API" }); var xmlFilename = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "Hg.Internal.Domain.xml")); }); builder.Services.AddDGHttpClient(); builder.Services.AddRedis(builder.Configuration); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment() || Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "PreProduction") { app.UseSwagger(); app.UseSwaggerUI(); } app.UseCors(MyAllowSpecificOrigins); app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.UseHttpLogging(); app.Run(); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); } finally { Log.CloseAndFlush(); }