using Exceptionless; using Zxd.WebApi.Workers; try { // Add services to the container. var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("Serilog.json") .AddJsonFile($"Serilog.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true) .Build(); 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[] { "zxd-crm-webapi" }) .CreateLogger(); Log.Logger = logger; builder.Services.AddLogging(logging => { logging.ClearProviders(); logging.AddSerilog(logger); }); builder.Services.AddExceptionless(builder.Configuration); Log.Information("Starting ZXD Service"); builder.Services.AddControllers() .AddApiResult() .AddApiSignature() .AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; options.JsonSerializerOptions.Converters.Add(new JsonOptionsExtensions()); }); builder.Services.AddDGHttpClient(); var MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; builder.Services.AddHostedService(); builder.Services.AddHostedService(); builder.Services.AddHostedService(); builder.Services.AddCors(option => { option.AddPolicy(MyAllowSpecificOrigins, policy => { policy.SetIsOriginAllowed(_ => true) .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); }); builder.Services.AddExceptionless(builder.Configuration); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Version = "v1", Title = "ZXD CORE API", Description = "ZXD CORE API" }); var xmlFilename = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "Zxd.Crm.Domain.xml")); }); builder.Services.AddRedis(builder.Configuration); builder.Services.AddOptions() .Configure(e => builder.Configuration.GetSection("SystemConfig").Bind(e)) .Configure(e => builder.Configuration.GetSection("ClientKey").Bind(e)); builder.Services.AddDGEntityFramework(options => { options.UseMySql(builder.Configuration.GetConnectionString("zxdcrm"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("zxdcrm"))); }); builder.Services.AddDGEntityFramework(options => { options.UseMySql(builder.Configuration.GetConnectionString("dncms"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("dncms"))); }); builder.Services.AddDGEntityFramework(options => { options.UseMySql(builder.Configuration.GetConnectionString("dncmsbase"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("dncmsbase"))); }); builder.Services.AddDGEntityFramework(options => { options.UseMySql(builder.Configuration.GetConnectionString("crm"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("crm"))); }); builder.Services.AddDGEntityFramework(options => { options.UseMySql(builder.Configuration.GetConnectionString("ssobase"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("ssobase"))); }); builder.Services.AddDGEntityFramework(options => { options.UseMySql(builder.Configuration.GetConnectionString("usercenter"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("usercenter"))); }); builder.Services.AddAutoIoc(typeof(IScopedDependency), LifeCycle.Scoped) .AddAutoIoc(typeof(ISingletonDependency), LifeCycle.Singleton) .AddAutoIoc(typeof(ITransientDependency), LifeCycle.Transient) .AddMapper(); var app = builder.Build(); app.UseCors(MyAllowSpecificOrigins); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment() || Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "PreProduction") { app.UseSwagger(); app.UseSwaggerUI(); } app.UseAuthorization(); app.UseExceptionless(); app.MapControllers(); app.Run(); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); } finally { Log.CloseAndFlush(); }