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.
119 lines
3.3 KiB
119 lines
3.3 KiB
3 weeks ago
|
|
||
|
|
||
|
|
||
|
using Hangfire;
|
||
|
using Hangfire.SqlServer;
|
||
|
using Microsoft.AspNetCore.Builder;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using Microsoft.Identity.Client;
|
||
|
using System;
|
||
|
using System.Reflection;
|
||
|
using System.Text.Json;
|
||
|
using System.Text.Json.Serialization;
|
||
|
|
||
|
using TaskManager.EntityFramework;
|
||
|
|
||
|
|
||
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// �������л�ȡ�����ַ���
|
||
|
var defaultConnection = builder.Configuration.GetConnectionString("Default");
|
||
|
|
||
|
builder.Services.AddHttpClient();
|
||
|
//builder.Services.AddScoped<LogController>();
|
||
|
//builder.Services.AddScoped<SUPPLIER_PRO_PLANING_CONTROLLER>();
|
||
|
|
||
|
//builder.Services.AddScoped<TaskConifgureController>();
|
||
|
|
||
|
//builder.Services.AddControllers()
|
||
|
// .AddJsonOptions(options =>
|
||
|
// {
|
||
|
// options.JsonSerializerOptions.Converters.Add(new CustomDateTimeConverter("yyyy-MM-dd HH:mm:ss"));
|
||
|
// options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||
|
// });
|
||
|
// ���ӷ���������
|
||
|
builder.Services.AddControllers();
|
||
|
|
||
|
// ���� JSON ���л�ѡ��������ж�ȡ���ԣ�
|
||
|
var jsonNamingPolicy = builder.Configuration.GetValue<string>("JsonOptions:PropertyNamingPolicy");
|
||
|
if (jsonNamingPolicy == "CamelCase")
|
||
|
{
|
||
|
builder.Services.AddControllers().AddJsonOptions(options =>
|
||
|
{
|
||
|
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||
|
});
|
||
|
}
|
||
|
// ��ѡ��֧�������������ԣ��� PascalCase��
|
||
|
else if (jsonNamingPolicy == "PascalCase")
|
||
|
{
|
||
|
// ...
|
||
|
}
|
||
|
//builder.Services.AddTransient<LogJobFilter>();
|
||
|
// ���� DbContext ʹ�� SQL Server �����ַ���
|
||
|
builder.Services.AddDbContext<JobDbContext>(options =>
|
||
|
options.UseSqlServer(defaultConnection));
|
||
|
|
||
|
// ���� Hangfire ʹ�� SQL Server �洢
|
||
|
builder.Services.AddHangfire(
|
||
|
|
||
|
|
||
|
configuration => configuration
|
||
|
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170) // ������ʽ���ü����汾
|
||
|
.UseSimpleAssemblyNameTypeSerializer() // �����������л�����ѡ��
|
||
|
.UseRecommendedSerializerSettings() // ʹ���Ƽ������л����ã���ѡ��
|
||
|
.UseSqlServerStorage(defaultConnection, new SqlServerStorageOptions
|
||
|
{
|
||
|
// �ɴ������ж�ȡ Hangfire �洢ѡ������С����Բ��Եȣ�
|
||
|
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||
|
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||
|
QueuePollInterval = TimeSpan.Zero,
|
||
|
UseRecommendedIsolationLevel = true,
|
||
|
DisableGlobalLocks = true
|
||
|
})
|
||
|
//.UseFilter(builder.Services.BuildServiceProvider().GetRequiredService<ILogger<LogJobFilter>>())
|
||
|
); // ������־����������ѡ��
|
||
|
|
||
|
|
||
|
// ���� Hangfire ���������ɴ������ж�ȡ�����߳����ȣ�
|
||
|
var workerCount = builder.Configuration.GetValue<int>("Hangfire:ServerOptions:WorkerCount", 10); // Ĭ��ֵ 10
|
||
|
builder.Services.AddHangfireServer(options =>
|
||
|
{
|
||
|
options.WorkerCount = workerCount;
|
||
|
// ��ѡ�����ö������ȼ�
|
||
|
options.Queues = builder.Configuration.GetSection("Hangfire:ServerOptions:Queues").Get<string[]>() ?? new[] { "default" };
|
||
|
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// ���� Swagger ����������...
|
||
|
builder.Services.AddEndpointsApiExplorer();
|
||
|
builder.Services.AddSwaggerGen();
|
||
|
|
||
|
var app = builder.Build();
|
||
|
|
||
|
|
||
|
app.UseHangfireDashboard();
|
||
|
|
||
|
// �������...
|
||
|
if (app.Environment.IsDevelopment())
|
||
|
{
|
||
|
app.UseSwagger();
|
||
|
app.UseSwaggerUI();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
app.UseAuthorization();
|
||
|
app.MapControllers();
|
||
|
app.Run();
|
||
|
|
||
|
|
||
|
// ʾ�����ͷ���
|