-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClaudeServiceCollectionExtensions.cs
More file actions
33 lines (28 loc) · 1.11 KB
/
ClaudeServiceCollectionExtensions.cs
File metadata and controls
33 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
namespace ManagedCode.ClaudeCodeSharpSDK.Extensions.AI.Extensions;
public static class ClaudeServiceCollectionExtensions
{
public static IServiceCollection AddClaudeChatClient(
this IServiceCollection services,
Action<ClaudeChatClientOptions>? configure = null)
{
ArgumentNullException.ThrowIfNull(services);
var options = new ClaudeChatClientOptions();
configure?.Invoke(options);
services.AddSingleton<IChatClient>(new ClaudeChatClient(options));
return services;
}
public static IServiceCollection AddKeyedClaudeChatClient(
this IServiceCollection services,
object serviceKey,
Action<ClaudeChatClientOptions>? configure = null)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(serviceKey);
var options = new ClaudeChatClientOptions();
configure?.Invoke(options);
services.AddKeyedSingleton<IChatClient>(serviceKey, new ClaudeChatClient(options));
return services;
}
}