Add XML doc to all service interfaces and implementations (#26)
- Update CLAUDE.md: replace incorrect 'no XML doc on internal code' rule with the correct convention (XML doc on all public methods and non-trivial private/protected helpers) - Restore /// <summary> on FileDownloadController private helpers (HandleRangeRequest, StreamRangeAsync) - Add full XML doc to all service contracts: ICaptchaVerifier, IEmailSender, ICvMatcherService, IJobTextExtractor, IJobTokenService, IDocumentClassifier, IRagService, ITextChunker, ITextExtractor, IEmailTemplateService, ITemplateService - Add /// <summary> and /// <inheritdoc /> to all concrete service classes and their methods: RecaptchaVerifier, EmailApiEmailSender, SmtpEmailDispatcher, CvMatcherService, JobTextExtractor, JobTokenService, RagService, DocumentClassifier, TextChunker, TextExtractor, HtmlJobSearcher, CvSearchEmailSender, CvSearchJobTask, EmailTemplateService, DbTemplateService Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,11 @@ using System.Collections.Concurrent;
|
||||
|
||||
namespace MyAi.Data.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Singleton implementation of <see cref="ITemplateService"/> that caches all templates from the
|
||||
/// <c>myAi.Templates</c> table and refreshes them every 10 minutes.
|
||||
/// Uses <see cref="IServiceScopeFactory"/> to resolve the scoped DbContext from a singleton lifetime.
|
||||
/// </summary>
|
||||
public sealed class DbTemplateService : ITemplateService
|
||||
{
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
@@ -20,6 +25,7 @@ public sealed class DbTemplateService : ITemplateService
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Get(string key, string language = "en")
|
||||
{
|
||||
EnsureCacheLoaded();
|
||||
@@ -35,6 +41,7 @@ public sealed class DbTemplateService : ITemplateService
|
||||
return key;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Render(string key, string language, params (string Key, string Value)[] placeholders)
|
||||
{
|
||||
var template = Get(key, language);
|
||||
@@ -43,6 +50,10 @@ public sealed class DbTemplateService : ITemplateService
|
||||
return template;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads all templates from the database when the cache TTL has expired.
|
||||
/// Swaps the cache atomically; logs an error and continues serving the stale cache on failure.
|
||||
/// </summary>
|
||||
private void EnsureCacheLoaded()
|
||||
{
|
||||
if (DateTime.UtcNow - _loadedAt < CacheTtl) return;
|
||||
@@ -66,5 +77,6 @@ public sealed class DbTemplateService : ITemplateService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Builds the dictionary key used in the cache.</summary>
|
||||
private static string CacheKey(string key, string language) => $"{key}::{language}";
|
||||
}
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
namespace MyAi.Data.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to localised string templates stored in the <c>myAi.Templates</c> table.
|
||||
/// Implementations are expected to cache templates and refresh periodically.
|
||||
/// </summary>
|
||||
public interface ITemplateService
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the template value for the given key and language.
|
||||
/// Falls back to <c>"en"</c> when the requested language has no entry.
|
||||
/// Returns the raw key string when no matching template is found.
|
||||
/// </summary>
|
||||
/// <param name="key">Template key (e.g. <c>"html.job-search-start.title"</c>).</param>
|
||||
/// <param name="language">Two-letter language code (e.g. <c>"en"</c>, <c>"ro"</c>).</param>
|
||||
/// <returns>Template value string.</returns>
|
||||
string Get(string key, string language = "en");
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the template and substitutes <c>{{placeholder}}</c> tokens with the provided values.
|
||||
/// </summary>
|
||||
/// <param name="key">Template key.</param>
|
||||
/// <param name="language">Two-letter language code.</param>
|
||||
/// <param name="placeholders">Named replacement pairs in the form <c>("name", value)</c>.</param>
|
||||
/// <returns>Rendered template string with all placeholders replaced.</returns>
|
||||
string Render(string key, string language, params (string Key, string Value)[] placeholders);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user