配置文件Configuration依赖注入
集中管理依赖注入
using AnotherWayToImplementRedis.Interfaces;
using AnotherWayToImplementRedis.Repositories;
namespace AnotherWayToImplementRedis.Configuration
{
public static class DependencyInjectionSettings
{
public static void DependencyInjection(this IServiceCollection services)
{
services.AddScoped<IUserRepository, UserRepository>();
}
}
}
Program.cs中添加调用
builder.Services.DependencyInjection(); builder.Services.ServiceExtensionSettings();
using System.Text.Json.Serialization;
namespace AnotherWayToImplementRedis.Configuration
{
public static class ServiceExtension
{
public static void ServiceExtensionSettings(this IServiceCollection services)
{
services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault;
});
}
}
}
浙公网安备 33010602011771号