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-12-19 21:10:34 +08:00
|
|
|
using BililiveRecorder.Core.Config.V3;
|
2021-02-23 18:03:37 +08:00
|
|
|
using BililiveRecorder.Core.Danmaku;
|
|
|
|
using BililiveRecorder.Core.Recording;
|
2022-05-11 19:07:21 +08:00
|
|
|
using BililiveRecorder.Core.Scripting;
|
2021-12-19 23:13:30 +08:00
|
|
|
using BililiveRecorder.Core.Templating;
|
2021-02-23 18:03:37 +08:00
|
|
|
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-12-19 21:10:34 +08:00
|
|
|
public static IServiceCollection AddRecorderConfig(this IServiceCollection services, ConfigV3 config) => services
|
2021-02-23 18:03:37 +08:00
|
|
|
.AddSingleton(config)
|
2021-12-19 21:10:34 +08:00
|
|
|
.AddSingleton(sp => sp.GetRequiredService<ConfigV3>().Global)
|
2021-02-23 18:03:37 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
public static IServiceCollection AddRecorder(this IServiceCollection services) => services
|
|
|
|
.AddSingleton<IMemoryStreamProvider, RecyclableMemoryStreamProvider>()
|
|
|
|
.AddRecorderPollyPolicy()
|
|
|
|
.AddRecorderApiClients()
|
|
|
|
.AddRecorderRecording()
|
|
|
|
.AddSingleton<IRecorder, Recorder>()
|
|
|
|
.AddSingleton<IRoomFactory, RoomFactory>()
|
|
|
|
.AddScoped<IBasicDanmakuWriter, BasicDanmakuWriter>()
|
2022-05-11 19:07:21 +08:00
|
|
|
.AddSingleton<UserScriptRunner>()
|
2021-02-23 18:03:37 +08:00
|
|
|
;
|
|
|
|
|
2021-03-01 21:38:13 +08:00
|
|
|
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>()
|
2022-05-16 23:28:31 +08:00
|
|
|
.AddSingleton<IHttpClientAccessor>(sp => sp.GetRequiredService<HttpApiClient>())
|
2021-02-23 18:03:37 +08:00
|
|
|
.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
|
2021-12-19 23:13:30 +08:00
|
|
|
.AddSingleton<FileNameGenerator>()
|
2021-02-23 18:03:37 +08:00
|
|
|
.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
|
|
|
}
|
|
|
|
}
|