about summary refs log tree commit diff
path: root/LibMatrix/Services/ServiceInstaller.cs
blob: 06ea9def0f9509c6f1e9c4c6ba4a233c5374fe83 (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
31
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace LibMatrix.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("[RMUCore/DI] No TieredStorageService has been registered!");
        //Add config
        services.AddSingleton(config ?? new RoryLibMatrixConfiguration());

        //Add services
        services.AddSingleton<HomeserverResolverService>(sp => new HomeserverResolverService(sp.GetRequiredService<ILogger<HomeserverResolverService>>()));

        // if (services.First(x => x.ServiceType == typeof(TieredStorageService)).Lifetime == ServiceLifetime.Singleton) {
        services.AddSingleton<HomeserverProviderService>();
        // }
        // else {
        // services.AddScoped<HomeserverProviderService>();
        // }

        // services.AddScoped<MatrixHttpClient>();
        return services;
    }
}

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