71 lines
2.9 KiB
C#
71 lines
2.9 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using MarketAlly.GitCommitEditor.Models.HistoryHealth;
|
|
using MarketAlly.GitCommitEditor.Options;
|
|
using MarketAlly.GitCommitEditor.Rewriters;
|
|
using MarketAlly.GitCommitEditor.Services;
|
|
|
|
namespace MarketAlly.GitCommitEditor.Extensions;
|
|
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds GitMessageImprover services to the service collection.
|
|
/// </summary>
|
|
public static IServiceCollection AddGitMessageImprover(
|
|
this IServiceCollection services,
|
|
Action<GitImproverOptions> configureOptions)
|
|
{
|
|
var options = new GitImproverOptions();
|
|
configureOptions(options);
|
|
options.ValidateAndThrow();
|
|
|
|
services.AddSingleton(options);
|
|
services.AddSingleton(options.Rules);
|
|
services.AddSingleton(options.Ai);
|
|
|
|
services.AddSingleton<IStateRepository>(sp =>
|
|
new FileStateRepository(options.StateFilePath));
|
|
|
|
// Cost tracking service (singleton to accumulate costs across session)
|
|
// Note: App should register ICostPersistenceProvider before calling AddGitMessageImprover
|
|
// for persistence support, or costs will only be tracked for the current session
|
|
services.AddSingleton<ICostTrackingService>(sp =>
|
|
{
|
|
var persistence = sp.GetService<ICostPersistenceProvider>();
|
|
return new CostTrackingService(persistence);
|
|
});
|
|
|
|
services.AddSingleton<ICommitMessageAnalyzer, CommitMessageAnalyzer>();
|
|
services.AddSingleton<IGitOperationsService, GitOperationsService>();
|
|
|
|
// Use DynamicCommitRewriter which switches between AI and Mock at runtime
|
|
// based on whether API key is configured
|
|
services.AddSingleton<ICommitMessageRewriter>(sp => new DynamicCommitRewriter(
|
|
sp.GetRequiredService<AiOptions>(),
|
|
sp.GetRequiredService<ICostTrackingService>()));
|
|
|
|
// History health analysis services
|
|
services.AddSingleton<HealthScoringWeights>();
|
|
services.AddSingleton<ICommitAnalyzer>(sp =>
|
|
new CommitAnalyzer(sp.GetRequiredService<CommitMessageRules>()));
|
|
services.AddSingleton<IHistoryHealthAnalyzer, HistoryHealthAnalyzer>();
|
|
services.AddSingleton<IHealthReportGenerator, HealthReportGenerator>();
|
|
|
|
// Cleanup executor
|
|
services.AddSingleton<ICleanupExecutor>(sp => new CleanupExecutor(
|
|
sp.GetRequiredService<IGitOperationsService>(),
|
|
sp.GetRequiredService<ICommitMessageAnalyzer>(),
|
|
sp.GetRequiredService<ICommitMessageRewriter>()));
|
|
|
|
// Git diagnostic service (AI-powered issue diagnosis)
|
|
services.AddSingleton<IGitDiagnosticService>(sp =>
|
|
new GitDiagnosticService(
|
|
sp.GetRequiredService<AiOptions>(),
|
|
sp.GetRequiredService<ICostTrackingService>()));
|
|
|
|
services.AddSingleton<IGitMessageImproverService, GitMessageImproverService>();
|
|
|
|
return services;
|
|
}
|
|
}
|