aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudServiceCollectionExtensions.cs
blob: 8854976677a22b2c6ca95f73322874ea65cbbaa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace CrupestApi.Commons.Crud;

public static class CrudServiceCollectionExtensions
{
    public static IServiceCollection AddCrudCore(this IServiceCollection services)
    {
        services.TryAddSingleton<IDbConnectionFactory, SqliteConnectionFactory>();
        services.TryAddSingleton<IColumnTypeProvider, ColumnTypeProvider>();
        services.TryAddSingleton<ITableInfoFactory, TableInfoFactory>();
        return services;
    }

    public static IServiceCollection AddCrud<TEntity>(this IServiceCollection services) where TEntity : class
    {
        AddCrudCore(services);

        services.TryAddScoped<CrudService<TEntity>>();
        services.TryAddScoped<EntityJsonHelper<TEntity>>();

        return services;
    }
}