From 0b35acf8cfd90909e2ab50f213f251b7adb7fcd9 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Tue, 19 Sep 2023 10:06:16 +0200 Subject: [PATCH 1/2] Add Service Lifetime to cache registration #117 --- src/ChatGptNet/IChatGptBuilderExtensions.cs | 5 +++-- src/ChatGptNet/version.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ChatGptNet/IChatGptBuilderExtensions.cs b/src/ChatGptNet/IChatGptBuilderExtensions.cs index b17b919..2490f56 100644 --- a/src/ChatGptNet/IChatGptBuilderExtensions.cs +++ b/src/ChatGptNet/IChatGptBuilderExtensions.cs @@ -13,16 +13,17 @@ public static class IChatGptBuilderExtensions /// /// The implementation of to use. /// The object to configure. + /// The of the service. /// The to further customize ChatGPT. /// is registered as singleton. /// /// - public static IChatGptBuilder WithCache(this IChatGptBuilder builder) + public static IChatGptBuilder WithCache(this IChatGptBuilder builder, ServiceLifetime lifetime = ServiceLifetime.Singleton) where TImplementation : class, IChatGptCache { ArgumentNullException.ThrowIfNull(builder); - builder.Services.Replace(ServiceDescriptor.Singleton()); + builder.Services.Replace(new ServiceDescriptor(typeof(IChatGptCache), typeof(TImplementation), lifetime)); return builder; } diff --git a/src/ChatGptNet/version.json b/src/ChatGptNet/version.json index 657bd92..1a27d9c 100644 --- a/src/ChatGptNet/version.json +++ b/src/ChatGptNet/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "2.4", + "version": "2.5", "publicReleaseRefSpec": [ "^refs/heads/master$" // we release out of master ], From 363e084430e6bf951e63bce066fcaf9746ccc1e4 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Tue, 19 Sep 2023 10:13:46 +0200 Subject: [PATCH 2/2] Documentation update #117 --- docs/ChatGptNet/IChatGptBuilderExtensions.md | 2 +- docs/ChatGptNet/IChatGptBuilderExtensions/WithCache.md | 10 ++++------ src/ChatGptNet/ChatGptServiceCollectionExtensions.cs | 6 +++--- src/ChatGptNet/IChatGptBuilderExtensions.cs | 3 +-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/ChatGptNet/IChatGptBuilderExtensions.md b/docs/ChatGptNet/IChatGptBuilderExtensions.md index f159d5c..ca80b7a 100644 --- a/docs/ChatGptNet/IChatGptBuilderExtensions.md +++ b/docs/ChatGptNet/IChatGptBuilderExtensions.md @@ -10,7 +10,7 @@ public static class IChatGptBuilderExtensions | name | description | | --- | --- | -| static [WithCache<TImplementation>](IChatGptBuilderExtensions/WithCache.md)(…) | Uses a custom cache implementation for conversation handling. | +| static [WithCache<TImplementation>](IChatGptBuilderExtensions/WithCache.md)(…) | Defines a custom cache implementation for conversation handling. | ## See Also diff --git a/docs/ChatGptNet/IChatGptBuilderExtensions/WithCache.md b/docs/ChatGptNet/IChatGptBuilderExtensions/WithCache.md index df49620..57d2ac3 100644 --- a/docs/ChatGptNet/IChatGptBuilderExtensions/WithCache.md +++ b/docs/ChatGptNet/IChatGptBuilderExtensions/WithCache.md @@ -1,9 +1,10 @@ # IChatGptBuilderExtensions.WithCache<TImplementation> method -Uses a custom cache implementation for conversation handling. +Defines a custom cache implementation for conversation handling. ```csharp -public static IChatGptBuilder WithCache(this IChatGptBuilder builder) +public static IChatGptBuilder WithCache(this IChatGptBuilder builder, + ServiceLifetime lifetime = ServiceLifetime.Singleton) where TImplementation : class, IChatGptCache ``` @@ -11,15 +12,12 @@ public static IChatGptBuilder WithCache(this IChatGptBuilder bu | --- | --- | | TImplementation | The implementation of [`IChatGptCache`](../IChatGptCache.md) to use. | | builder | The [`IChatGptBuilder`](../IChatGptBuilder.md) object to configure. | +| lifetime | The ServiceLifetime of the service. | ## Return Value The [`IChatGptBuilder`](../IChatGptBuilder.md) to further customize ChatGPT. -## Remarks - -*TImplementation* is registered as singleton. - ## See Also * interface [IChatGptBuilder](../IChatGptBuilder.md) diff --git a/src/ChatGptNet/ChatGptServiceCollectionExtensions.cs b/src/ChatGptNet/ChatGptServiceCollectionExtensions.cs index 3b043a9..a8504ef 100644 --- a/src/ChatGptNet/ChatGptServiceCollectionExtensions.cs +++ b/src/ChatGptNet/ChatGptServiceCollectionExtensions.cs @@ -18,7 +18,7 @@ public static class ChatGptServiceCollectionExtensions /// The to configure options. /// A that can be used to further customize ChatGPT. /// This method automatically adds a that is used to save conversation history for chat completion. - /// It is possibile to use to specify another cache implementation. + /// It is possibile to use to specify another cache implementation. /// /// /// @@ -47,7 +47,7 @@ public static IChatGptBuilder AddChatGpt(this IServiceCollection services, Actio /// The name of the configuration section that holds ChatGPT settings (default: ChatGPT). /// A that can be used to further customize ChatGPT. /// This method automatically adds a that is used to save conversation history for chat completion. - /// It is possibile to use to specify another cache implementation. + /// It is possibile to use to specify another cache implementation. /// /// /// @@ -75,7 +75,7 @@ public static IChatGptBuilder AddChatGpt(this IServiceCollection services, IConf /// A that can be used to further customize ChatGPT. /// Use this this method if it is necessary to dynamically set options (for example, using other services via dependency injection). /// This method automatically adds a that is used to save conversation history for chat completion. - /// It is possibile to use to specify another cache implementation. + /// It is possibile to use to specify another cache implementation. /// /// /// diff --git a/src/ChatGptNet/IChatGptBuilderExtensions.cs b/src/ChatGptNet/IChatGptBuilderExtensions.cs index 2490f56..298c0e6 100644 --- a/src/ChatGptNet/IChatGptBuilderExtensions.cs +++ b/src/ChatGptNet/IChatGptBuilderExtensions.cs @@ -9,13 +9,12 @@ namespace ChatGptNet; public static class IChatGptBuilderExtensions { /// - /// Uses a custom cache implementation for conversation handling. + /// Defines a custom cache implementation for conversation handling. /// /// The implementation of to use. /// The object to configure. /// The of the service. /// The to further customize ChatGPT. - /// is registered as singleton. /// /// public static IChatGptBuilder WithCache(this IChatGptBuilder builder, ServiceLifetime lifetime = ServiceLifetime.Singleton)