refactor: create interface for store

This commit is contained in:
Stevan Freeborn
2025-05-28 21:59:50 -05:00
parent 887b95f798
commit 6479531126
5 changed files with 22 additions and 5 deletions
+1 -1
View File
@@ -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);
}
}