refactor: create interface for store
This commit is contained in:
@@ -41,7 +41,7 @@ builder.Services.AddSingleton(TimeProvider.System);
|
||||
builder.Services.AddSingleton<ConcurrentQueue<SubscribeTask>>();
|
||||
builder.Services.AddHostedService<SubscriptionWorker>();
|
||||
|
||||
builder.Services.AddSingleton<LastPostedStreamStore>();
|
||||
builder.Services.AddSingleton<ILastPostedStreamStore, LastPostedStreamStore>();
|
||||
|
||||
builder.Services.AddOptionsWithValidateOnStart<DiscordNotificationOptions>()
|
||||
.BindConfiguration(nameof(DiscordNotificationOptions))
|
||||
|
||||
@@ -8,7 +8,7 @@ internal static class NotificationHandler
|
||||
[FromServices] IYouTubeDataApiClient youTubeDataApiClient,
|
||||
[FromServices] IDiscordRestClient discordRestClient,
|
||||
[FromServices] IOptionsMonitor<DiscordNotificationOptions> discordNotificationOptions,
|
||||
[FromServices] LastPostedStreamStore lastPostedStream,
|
||||
[FromServices] ILastPostedStreamStore lastPostedStream,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace StevesBot.Webhook.YouTube;
|
||||
|
||||
internal interface ILastPostedStreamStore : IStore<string>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace StevesBot.Webhook.YouTube;
|
||||
|
||||
internal interface IStore<T>
|
||||
{
|
||||
void SetValue(T value);
|
||||
bool HasValue(T value);
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
namespace StevesBot.Webhook.YouTube;
|
||||
|
||||
internal class LastPostedStreamStore
|
||||
internal class LastPostedStreamStore : ILastPostedStreamStore
|
||||
{
|
||||
public string Value { get; private set; } = string.Empty;
|
||||
private string _value = string.Empty;
|
||||
|
||||
public void SetValue(string value)
|
||||
{
|
||||
Value = value;
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public bool HasValue(string value)
|
||||
{
|
||||
return _value.Equals(value, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user