forked from xiongyuxing/tiku-backend.net
44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Npgsql;
|
|
using Tiku.Application.Auth;
|
|
using Tiku.Application.Catalog;
|
|
using Tiku.Application.Content;
|
|
using Tiku.Application.QuestionBanks;
|
|
using Tiku.Infrastructure.Auth;
|
|
using Tiku.Infrastructure.Catalog;
|
|
using Tiku.Infrastructure.Content;
|
|
using Tiku.Infrastructure.Persistence;
|
|
using Tiku.Infrastructure.QuestionBanks;
|
|
|
|
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.AddHttpClient<IWechatOAuthClient, WechatOAuthClient>();
|
|
services.AddScoped<IAuthService, AuthService>();
|
|
services.AddScoped<ICatalogQueryService, CatalogQueryService>();
|
|
services.AddScoped<IContentNavigationQueryService, ContentNavigationQueryService>();
|
|
services.AddScoped<IQuestionBankQueryService, QuestionBankQueryService>();
|
|
|
|
return services;
|
|
}
|
|
}
|