BililiveRecorder/BililiveRecorder.Core/DependencyInjectionExtensions.cs

52 lines
2.4 KiB
C#
Raw Normal View History

2021-02-08 16:51:19 +08:00
using BililiveRecorder.Core;
2021-02-23 18:03:37 +08:00
using BililiveRecorder.Core.Api;
using BililiveRecorder.Core.Api.Danmaku;
using BililiveRecorder.Core.Api.Http;
2021-02-08 16:51:19 +08:00
using BililiveRecorder.Core.Config.V2;
2021-02-23 18:03:37 +08:00
using BililiveRecorder.Core.Danmaku;
using BililiveRecorder.Core.Recording;
using BililiveRecorder.Flv;
2021-02-08 16:51:19 +08:00
using Microsoft.Extensions.DependencyInjection;
2021-02-23 18:03:37 +08:00
using Polly.Registry;
2021-02-08 16:51:19 +08:00
namespace BililiveRecorder.DependencyInjection
{
public static class DependencyInjectionExtensions
{
2021-02-23 18:03:37 +08:00
public static IServiceCollection AddRecorderConfig(this IServiceCollection services, ConfigV2 config) => services
.AddSingleton(config)
.AddSingleton(sp => sp.GetRequiredService<ConfigV2>().Global)
;
public static IServiceCollection AddRecorder(this IServiceCollection services) => services
.AddSingleton<IMemoryStreamProvider, RecyclableMemoryStreamProvider>()
.AddRecorderPollyPolicy()
.AddRecorderApiClients()
.AddRecorderRecording()
.AddSingleton<IRecorder, Recorder>()
.AddSingleton<IRoomFactory, RoomFactory>()
.AddScoped<IBasicDanmakuWriter, BasicDanmakuWriter>()
;
private static IServiceCollection AddRecorderPollyPolicy(this IServiceCollection services) => services
.AddSingleton<PollyPolicy>()
.AddSingleton<IReadOnlyPolicyRegistry<string>>(sp => sp.GetRequiredService<PollyPolicy>())
;
2021-02-23 18:03:37 +08:00
public static IServiceCollection AddRecorderApiClients(this IServiceCollection services) => services
.AddSingleton<HttpApiClient>()
.AddSingleton<PolicyWrappedApiClient<HttpApiClient>>()
.AddSingleton<IApiClient>(sp => sp.GetRequiredService<PolicyWrappedApiClient<HttpApiClient>>())
.AddSingleton<IDanmakuServerApiClient>(sp => sp.GetRequiredService<PolicyWrappedApiClient<HttpApiClient>>())
.AddScoped<IDanmakuClient, DanmakuClient>()
;
public static IServiceCollection AddRecorderRecording(this IServiceCollection services) => services
.AddScoped<IRecordTaskFactory, RecordTaskFactory>()
2021-03-03 19:04:37 +08:00
.AddScoped<IFlvProcessingContextWriterFactory, FlvProcessingContextWriterWithFileWriterFactory>()
2021-02-23 18:03:37 +08:00
.AddScoped<IFlvTagReaderFactory, FlvTagReaderFactory>()
.AddScoped<ITagGroupReaderFactory, TagGroupReaderFactory>()
;
2021-02-08 16:51:19 +08:00
}
}