39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
|
|
using Gatedge.ScanCode.Services;
|
|||
|
|
using Gatedge.ScanCode.Services.IServices;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using System.Text.Json;
|
|||
|
|
|
|||
|
|
namespace Gatedge.ScanCode.Extension
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 服务扩展
|
|||
|
|
/// </summary>
|
|||
|
|
public static class ServiceExtension
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 添加MVC服务,并配置默认的输出格式为JSON
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="services"></param>
|
|||
|
|
public static void ConfigureServices(this IServiceCollection services)
|
|||
|
|
{
|
|||
|
|
// 添加MVC服务,并配置默认的输出格式为JSON
|
|||
|
|
services.AddControllers().AddJsonOptions(options =>
|
|||
|
|
{
|
|||
|
|
// 可以在这里配置JSON序列化选项,例如日期格式、驼峰命名等
|
|||
|
|
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
|||
|
|
options.JsonSerializerOptions.WriteIndented = true;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 注册Bean服务
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="service"></param>
|
|||
|
|
public static void ConfigureCore(this IServiceCollection service)
|
|||
|
|
{
|
|||
|
|
service.AddSingleton<IAuthorizationMiddlewareResultHandler, Middleware.AuthorizationMiddleware>();
|
|||
|
|
service.AddTransient<IAccountService, AccountService>();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|