void.cat/VoidCat/Services/Paywall/PaywallFactory.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2022-02-21 12:54:57 +00:00
using VoidCat.Model.Paywall;
using VoidCat.Services.Abstractions;
2022-02-22 14:20:31 +00:00
using VoidCat.Services.Strike;
2022-02-21 12:54:57 +00:00
namespace VoidCat.Services.Paywall;
public class PaywallFactory : IPaywallFactory
{
private readonly IServiceProvider _services;
public PaywallFactory(IServiceProvider services)
{
_services = services;
}
public ValueTask<IPaywallProvider> CreateProvider(PaywallServices svc)
{
return ValueTask.FromResult<IPaywallProvider>(svc switch
{
PaywallServices.Strike => _services.GetRequiredService<StrikePaywallProvider>(),
_ => throw new ArgumentException("Must have a paywall config", nameof(svc))
});
}
}
public static class Paywall
{
2022-06-06 21:51:25 +00:00
public static void AddVoidPaywall(this IServiceCollection services)
2022-02-21 12:54:57 +00:00
{
services.AddTransient<IPaywallFactory, PaywallFactory>();
2022-02-21 22:35:06 +00:00
services.AddTransient<IPaywallStore, PaywallStore>();
2022-06-06 21:51:25 +00:00
2022-02-21 12:54:57 +00:00
// strike
services.AddTransient<StrikeApi>();
services.AddTransient<StrikePaywallProvider>();
services.AddTransient<IPaywallProvider>((svc) => svc.GetRequiredService<StrikePaywallProvider>());
}
}