95 lines
2.4 KiB
C#
95 lines
2.4 KiB
C#
|
|
using langguanApi.Common.Redis;
|
|||
|
|
using langguanApi.Extensions;
|
|||
|
|
using langguanApi.Extensions.AutoDI;
|
|||
|
|
using langguanApi.Middleware;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using Microsoft.OpenApi.Models;
|
|||
|
|
using System.Text.Json;
|
|||
|
|
|
|||
|
|
var builder = WebApplication.CreateBuilder(args);
|
|||
|
|
|
|||
|
|
|
|||
|
|
// Add services to the container.
|
|||
|
|
|
|||
|
|
builder.Services.AddControllers(options =>
|
|||
|
|
{
|
|||
|
|
options.Filters.Add<CustomerExceptionFilter>();
|
|||
|
|
}).AddNewtonsoftJson(option =>
|
|||
|
|
{
|
|||
|
|
option.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
|
|||
|
|
option.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|||
|
|
|
|||
|
|
}).AddJsonOptions(option =>
|
|||
|
|
{
|
|||
|
|
option.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
|||
|
|
});
|
|||
|
|
//swagger
|
|||
|
|
builder.Services.AddSwaggerGen(
|
|||
|
|
options =>
|
|||
|
|
{
|
|||
|
|
options.SwaggerDoc("v1", new OpenApiInfo()
|
|||
|
|
{
|
|||
|
|
Title = "Title",
|
|||
|
|
Version = "v1",
|
|||
|
|
Description = "Description",
|
|||
|
|
});
|
|||
|
|
var path = Path.Combine(AppContext.BaseDirectory, "langguanApi.xml");
|
|||
|
|
options.IncludeXmlComments(path, true);
|
|||
|
|
options.OrderActionsBy(_ => _.RelativePath);
|
|||
|
|
});
|
|||
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|||
|
|
builder.Services.AddEndpointsApiExplorer();
|
|||
|
|
|
|||
|
|
//redis
|
|||
|
|
var redisoptions = builder.Configuration.GetSection("Redis").Get<RedisOptions>();
|
|||
|
|
if (redisoptions != null)
|
|||
|
|
{
|
|||
|
|
builder.Services.AddRedis(options =>
|
|||
|
|
{
|
|||
|
|
options.Port = redisoptions.Port;
|
|||
|
|
options.Server = redisoptions.Server;
|
|||
|
|
options.Index = redisoptions.Index;
|
|||
|
|
options.Password = redisoptions.Password;
|
|||
|
|
options.Key = redisoptions.Key;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
//<2F>Զ<EFBFBD>ע<EFBFBD><D7A2>
|
|||
|
|
builder.Services.ServicesAutoInjectionExtension();
|
|||
|
|
builder.Services.AddSocketService();
|
|||
|
|
//cross domain
|
|||
|
|
builder.Services.AddCors(options =>
|
|||
|
|
{
|
|||
|
|
options.AddPolicy("CorsPolicy", builder =>
|
|||
|
|
{
|
|||
|
|
builder.AllowAnyOrigin();
|
|||
|
|
builder.AllowAnyMethod();
|
|||
|
|
builder.AllowAnyHeader();
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
var app = builder.Build();
|
|||
|
|
ServiceLocator.Instance = app.Services;
|
|||
|
|
|
|||
|
|
|
|||
|
|
// Configure the HTTP request pipeline.
|
|||
|
|
if (app.Environment.IsDevelopment())
|
|||
|
|
{
|
|||
|
|
app.UseSwagger();
|
|||
|
|
app.UseSwaggerUI();
|
|||
|
|
}
|
|||
|
|
app.UseSwagger();
|
|||
|
|
app.UseSwaggerUI();
|
|||
|
|
app.UseCors("CorsPolicy");
|
|||
|
|
//app.UseAuthorization();
|
|||
|
|
|
|||
|
|
app.MapControllers();
|
|||
|
|
|
|||
|
|
app.Run();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static class ServiceLocator
|
|||
|
|
{
|
|||
|
|
public static IServiceProvider Instance { get; set; }
|
|||
|
|
}
|