96 lines
4.5 KiB
C#
96 lines
4.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Npgsql;
|
|
using Tiku.Application.Assets;
|
|
using Tiku.Application.Auth;
|
|
using Tiku.Application.Catalog;
|
|
using Tiku.Application.Commerce;
|
|
using Tiku.Application.Content;
|
|
using Tiku.Application.Growth;
|
|
using Tiku.Application.Learning;
|
|
using Tiku.Application.QuestionBanks;
|
|
using Tiku.Application.Profile;
|
|
using Tiku.Application.Points;
|
|
using Tiku.Application.Scoreline;
|
|
using Tiku.Application.Storage;
|
|
using Tiku.Application.StudyContent;
|
|
using Tiku.Application.TenantAdmin;
|
|
using Tiku.Infrastructure.Assets;
|
|
using Tiku.Infrastructure.Auth;
|
|
using Tiku.Infrastructure.Catalog;
|
|
using Tiku.Infrastructure.Commerce;
|
|
using Tiku.Infrastructure.Content;
|
|
using Tiku.Infrastructure.Growth;
|
|
using Tiku.Infrastructure.Learning;
|
|
using Tiku.Infrastructure.Persistence;
|
|
using Tiku.Infrastructure.Profile;
|
|
using Tiku.Infrastructure.Points;
|
|
using Tiku.Infrastructure.QuestionBanks;
|
|
using Tiku.Infrastructure.Scoreline;
|
|
using Tiku.Infrastructure.Storage;
|
|
using Tiku.Infrastructure.StudyContent;
|
|
using Tiku.Infrastructure.TenantAdmin;
|
|
|
|
namespace Tiku.Infrastructure;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddInfrastructure(
|
|
this IServiceCollection services,
|
|
string connectionString)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(connectionString);
|
|
|
|
services.AddSingleton(_ => NpgsqlDataSource.Create(connectionString));
|
|
services.AddDbContextPool<TikuDbContext>((serviceProvider, options) =>
|
|
{
|
|
var dataSource = serviceProvider.GetRequiredService<NpgsqlDataSource>();
|
|
options.UseNpgsql(dataSource, npgsql =>
|
|
npgsql.MigrationsAssembly(typeof(TikuDbContext).Assembly.FullName));
|
|
});
|
|
services.AddScoped<IPasswordHasher, PasswordHasher>();
|
|
services.AddScoped<ITokenService, TokenService>();
|
|
services.AddScoped<ISessionService, SessionService>();
|
|
services.AddScoped<ISmsVerificationService, SmsVerificationService>();
|
|
services.AddScoped<IWechatOAuthClient, WechatOAuthClient>();
|
|
services.AddScoped<IAuthService, AuthService>();
|
|
services.AddScoped<ICatalogQueryService, CatalogQueryService>();
|
|
services.AddScoped<IContentNavigationQueryService, ContentNavigationQueryService>();
|
|
services.AddScoped<IContentManagementService, ContentManagementService>();
|
|
services.AddScoped<IDirectContentService, DirectContentService>();
|
|
services.AddScoped<IQuestionBankQueryService, QuestionBankQueryService>();
|
|
services.AddScoped<IProfileService, ProfileService>();
|
|
services.AddScoped<IScorelineQueryService, ScorelineQueryService>();
|
|
services.AddScoped<IStudyContentQueryService, StudyContentQueryService>();
|
|
services.AddScoped<IAssetQueryService, AssetQueryService>();
|
|
services.AddScoped<IAssetAccessService, AssetAccessService>();
|
|
services.AddScoped<IAssetManagementService, AssetManagementService>();
|
|
services.AddScoped<ILearningActivityService, LearningActivityService>();
|
|
services.AddScoped<ITenantAdminDirectService, TenantAdminDirectService>();
|
|
services.AddScoped<ICommerceService, CommerceService>();
|
|
services.AddScoped<ICommerceAdminService, CommerceAdminService>();
|
|
services.AddScoped<IPointService, PointService>();
|
|
services.AddScoped<IReferralQrcodeGenerator, ReferralQrcodeGenerator>();
|
|
services.AddScoped<IReferralService, ReferralService>();
|
|
services.AddScoped<ICrmService, CrmService>();
|
|
services.AddScoped<ICommissionService, CommissionService>();
|
|
services.AddScoped<ITenantSecretService, TenantSecretService>();
|
|
services.AddScoped<IPaymentProviderConfigService, PaymentProviderConfigService>();
|
|
services.AddScoped<IPaymentProviderGateway, PaymentProviderGateway>();
|
|
services.AddScoped<IPaymentProvider, ManualPaymentProvider>();
|
|
services.AddScoped<IPaymentProvider, WechatPayProvider>();
|
|
services.AddScoped<IPaymentProvider, AlipayProvider>();
|
|
services.AddOptions<AliyunOssOptions>()
|
|
.Validate(
|
|
AliyunOssOptions.BeValid,
|
|
"Aliyun OSS presign default expiration must be positive.");
|
|
services.AddOptions<ObjectStorageOptions>()
|
|
.Validate(
|
|
ObjectStorageOptions.BeValid,
|
|
"Storage options must include a default provider, default bucket and positive max upload bytes.");
|
|
services.AddSingleton<IObjectStorageService, AliyunOssObjectStorageService>();
|
|
|
|
return services;
|
|
}
|
|
}
|