30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
using GymLogAI.Application.Interfaces;
|
|
using GymLogAI.Core.Abstractions;
|
|
using GymLogAI.Persistence.Infrastructure;
|
|
using GymLogAI.Persistence.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace GymLogAI.Persistence;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var connectionString = configuration.GetConnectionString("Postgres")
|
|
?? "Host=localhost;Port=5432;Database=gymlogai;Username=postgres;Password=postgres";
|
|
|
|
services.AddDbContext<AppDbContext>(options => options.UseNpgsql(connectionString));
|
|
|
|
services.AddScoped<IUserRepository, UserRepository>();
|
|
services.AddScoped<ITelegramMessageRepository, TelegramMessageRepository>();
|
|
services.AddScoped<IWorkoutRepository, WorkoutRepository>();
|
|
services.AddScoped<IExerciseRepository, ExerciseRepository>();
|
|
services.AddSingleton<IClock, SystemClock>();
|
|
services.AddSingleton<IIdGenerator, GuidIdGenerator>();
|
|
|
|
return services;
|
|
}
|
|
}
|