Files
Luna/Luna.Providers/Extensions/ServiceProviderExtensions.cs
T
darman 1c42c8c006 Add provider abstraction layer with Mistral and Ollama implementations
Define IProvider interface and implement concrete providers for Mistral
(with custom DTOs for chat completion API) and Ollama (via OllamaSharp).
Includes DI registration extensions using Microsoft.Extensions.AI.
2026-04-04 04:10:39 +02:00

28 lines
830 B
C#

using Luna.Configuration;
using Luna.Providers.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace Luna.Providers.Extensions;
public static class ServiceProviderExtensions
{
extension(IServiceProvider provider)
{
public TProvider GetProvider<TProvider>(string? name = null)
where TProvider : IProvider
{
name ??= TProvider.Name;
return provider.GetRequiredKeyedService<TProvider>(name);
}
public ProviderOptions GetProviderOptions<TProvider>(string? name = null)
where TProvider : IProvider
{
name ??= TProvider.Name;
return provider
.GetRequiredService<IOptionsMonitor<ProviderOptions>>()
.Get(name);
}
}
}