You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.5 KiB
72 lines
2.5 KiB
using Binance.TradeRobot.API.Filters;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace Binance.TradeRobot.API
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
var fsql = new FreeSql.FreeSqlBuilder().UseConnectionString(FreeSql.DataType.SqlServer, Configuration.GetConnectionString("DB")).Build();
|
|
services.AddSingleton(typeof(IFreeSql), fsql);
|
|
|
|
var idOption = new IdGeneratorOptions(1);
|
|
var idGenerator = new DefaultIdGenerator(idOption);
|
|
services.AddSingleton(typeof(IIdGenerator), idGenerator);
|
|
|
|
services.AddHttpContextAccessor();
|
|
services.AddHttpClient();
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(p =>
|
|
{
|
|
p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
|
|
});
|
|
});
|
|
services.AddControllers(configure =>
|
|
{
|
|
configure.Filters.Add<ResultFilter>();
|
|
}).AddNewtonsoftJson(setupAction =>
|
|
{
|
|
setupAction.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
|
setupAction.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
setupAction.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
|
|
setupAction.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
|
|
});
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|