Files
StopShopping/StopShopping.Services/Extensions/ServicesExtensions.cs
2026-03-30 11:07:30 +08:00

47 lines
1.7 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using StopShopping.EF;
using StopShopping.Services;
using StopShopping.Services.Extensions;
using StopShopping.Services.Implementions;
namespace Microsoft.Extensions.DependencyInjection;
public static class ServicesExtensions
{
public static IServiceCollection AddServices(
this IServiceCollection services,
Action<DbContextOptionsBuilder> dbContextOptions,
IConfiguration appOptions,
IConfiguration openPlatformOptions)
{
services.AddDbContext<StopShoppingContext>(dbContextOptions);
services.Configure<AppOptions>(appOptions);
services.AddHttpClient(Consts.FILE_API_CLIENT_NAME, (sp, client) =>
{
var options = sp.GetRequiredService<IOptions<AppOptions>>();
client.BaseAddress = new Uri(options.Value.FileApiLocalDomain);
});
services.AddSingleton<ICipherService, CipherService>();
services.AddSingleton<ISerialNoGenerator, NanoidSerialNoGenerator>();
services.AddScoped<IFileService, FileService>();
services.AddScoped<IDistrictService, DistrictService>();
services.AddScoped<IClaimsService, ClaimsService>();
services.AddScoped<IAccessTokenService, AccessTokenService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<ICategoryService, CategoryService>();
services.AddScoped<IProductService, ProductService>();
services.AddScoped<IRequestService, RequestService>();
services.AddScoped<IReplyService, ReplyService>();
services.AddOpenPlatformServices(openPlatformOptions);
return services;
}
}