about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Services/ServiceInstaller.cs
blob: bd5b1bd95ce53351b901beeaf71744282cc79675 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using MatrixRoomUtils.Core.Extensions;
using Microsoft.Extensions.DependencyInjection;

namespace MatrixRoomUtils.Core.Services;

public static class ServiceInstaller {

    public static IServiceCollection AddRoryLibMatrixServices(this IServiceCollection services, RoryLibMatrixConfiguration? config = null) {
        //Check required services
        if (!services.Any(x => x.ServiceType == typeof(TieredStorageService)))
            throw new Exception("[MRUCore/DI] No TieredStorageService has been registered!");
        //Add config
        if(config is not null)
            services.AddSingleton(config);
        else {
            services.AddSingleton(new RoryLibMatrixConfiguration());
        }
        //Add services
        services.AddSingleton<HomeserverProviderService>();
        services.AddSingleton<HomeserverResolverService>();
        // services.AddScoped<MatrixHttpClient>();
        return services;
    }


}

public class RoryLibMatrixConfiguration {
    public string AppName { get; set; } = "Rory&::LibMatrix";
}