Skip to content

Commit

Permalink
Merge pull request #57 from Encamina/@fbelizon/issue-inject-token-fun…
Browse files Browse the repository at this point in the history
…ction-on-document-provider

Added optional parameter to `AddDefaultDocumentConnectorProvider` and `AddDefaultDocumentContentExtractor`
  • Loading branch information
fjbelizon authored Jan 22, 2024
2 parents ddd61f6 + 4a238cb commit a72a083
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Previous classification is not required if changes are simple or all belong to t
- Fixed some typos and grammatical errors (mostly on code comments).
- Added new extension method `AddDefaultDocumentConnectorProvider` in `Encamina.Enmarcha.SemanticKernel.Connectors.Document` to get access to a default implementation of a `IDocumentConnector`.
- Updated sample projects with latest changes.
- Overloaded `AddDefaultDocumentConnectorProvider` and `AddDefaultDocumentContentExtractor` methods with a parameter for pass it a function to calculate the length of a text and inject it as a dependency.

## [8.1.1]

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<PropertyGroup>
<VersionPrefix>8.1.2</VersionPrefix>
<VersionSuffix>preview-8</VersionSuffix>
<VersionSuffix>preview-9</VersionSuffix>
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public static IServiceCollection AddDefaultDocumentContentExtractor(this IServic
return services.AddSingleton<IDocumentContentExtractor, DefaultDocumentContentExtractor>();
}

/// <summary>
/// Adds a default implementation of <see cref="IDocumentContentExtractor"/> to the specified <see cref="IServiceCollection"/> as a singleton service.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
/// <param name="lengthFunction">A length function to use when extracting content from documents.</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection AddDefaultDocumentContentExtractor(this IServiceCollection services, Func<string, int> lengthFunction)
{
services.AddSingleton(lengthFunction);
return services.AddDefaultDocumentContentExtractor();
}

/// <summary>
/// Adds a default implementation of <see cref="IDocumentConnectorProvider"/> to the specified <see cref="IServiceCollection"/> as a singleton service.
/// </summary>
Expand All @@ -28,4 +40,16 @@ public static IServiceCollection AddDefaultDocumentConnectorProvider(this IServi
{
return services.AddSingleton<IDocumentConnectorProvider, DefaultDocumentContentExtractor>();
}

/// <summary>
/// Adds a default implementation of <see cref="IDocumentConnectorProvider"/> to the specified <see cref="IServiceCollection"/> as a singleton service.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
/// <param name="lengthFunction">A length function to use when extracting content from documents.</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection AddDefaultDocumentConnectorProvider(this IServiceCollection services, Func<string, int> lengthFunction)
{
services.AddSingleton(lengthFunction);
return services.AddDefaultDocumentConnectorProvider();
}
}

0 comments on commit a72a083

Please sign in to comment.