-
Notifications
You must be signed in to change notification settings - Fork 4.4k
.Net: SqlServer dependency injection extension methods #11909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.Net: SqlServer dependency injection extension methods #11909
Conversation
|
|
||
| protected abstract void RegisterVectorStore(IServiceCollection services, ServiceLifetime lifetime, object? serviceKey = null); | ||
|
|
||
| protected abstract void RegisterCollection(IServiceCollection services, ServiceLifetime lifetime, string collectionName = "name", object? serviceKey = null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roji regarding your comment about exposing a list of delegates from https://github.com/microsoft/semantic-kernel/pull/11594/files#r2049050430, I propose to take what I have now and let me shape the final form of the base DI test class in the next PR, once I apply the same pattern to all the connectors and have the full picture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely no problem to finalize the tests later! I do think we'll ideally want to cover more than just one register method (which is what this allows), but definitely ok for now.
roji
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamsitnik looks great! Here's a first round of feedback.
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/VectorDataIntegrationTests/VectorDataIntegrationTests/DependencyInjectionTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/VectorDataIntegrationTests/VectorDataIntegrationTests/DependencyInjectionTests.cs
Outdated
Show resolved
Hide resolved
|
|
||
| [Theory] | ||
| [MemberData(nameof(LiftetimesAndKeys))] | ||
| public virtual void CanRegisterConcreteTypeVectorStoreAfterSomeAbstractionHasBeenRegistered(ServiceLifetime lifetime, object? serviceKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally very much use snake_case (see filter tests) for test names precisely for this kind of super long test name, which I personally find really hard to read (there's a reason humans put spaces between words 🤣 ).
But definitely not blocking, we're already inconsistent on this - we'll clean up afterwards.
dotnet/src/VectorDataIntegrationTests/VectorDataIntegrationTests/DependencyInjectionTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/VectorDataIntegrationTests/VectorDataIntegrationTests/DependencyInjectionTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Shay Rojansky <roji@roji.org>
- move the extension methods to Microsoft.Extensions.DependencyInjection namespace as they extend IServiceCollection from this namespace - resolve IEmbeddingGenerator and set it for the option bag - use Add rather than TryAdd - add note about HybridSearch - remove the need to use Hosting - renames and simplification
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
- reduce code duplication - reduce XML docs duplication - create a copy of the option bag to avoid modifying user provided input
roji
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See mainly comment about refactoring out the options copying logic to an internal copy constructors, otherwise LGTM!
dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
| /// Registers a <see cref="SqlServerVectorStore"/> as <see cref="VectorStore"/>, with the specified connection string and service lifetime. | ||
| /// </summary> | ||
| /// <inheritdoc cref="AddVectorStore"/> | ||
| public static IServiceCollection AddSqlServerVectorStore( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought - would be helpful to use #region to group together methods which belong together (e.g. the keyed/non-keyed pair plus the private implementation they delegate to). Not critical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me using regions: https://youtu.be/J0jA89ro48w?t=201
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahahahaha yeah I thought when I proposed this that it might be a bit... controversial ;)
…ance they are going to get updated when a new property is introduced
d5d52f8
into
microsoft:feature-vector-data-preb3
It's a resurrected and updated #11594.
Please keep in mind that the main point is establishing a pattern that is going to be applied to all other connectors:
IServiceCollection servicesby creating a new static class called '{$ConnectorName}ServiceCollectionExtensions', part of the Microsoft.SemanticKernel namespaceAdd{$ConnectorName}VectorStoreandAdd{$ConnectorName}Collection. And a Keyed variant withAddKeyedprefix.ServiceLifetime.Singletonis the default, but users can customize itFuncwhich acceptsIServiceProviderto obtain every setting (to be able to read from the config or resolve from the DI)string connectionStringfixes #10948