feat: Add dependency injection support in a separate hosting package - #65
Closed
kinyoklion wants to merge 1 commit into
Closed
feat: Add dependency injection support in a separate hosting package#65kinyoklion wants to merge 1 commit into
kinyoklion wants to merge 1 commit into
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
|
@cursor review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirements
Describe the solution you've provided
Adds
LaunchDarkly.OpenFeature.ServerProvider.Hosting, a new package containing the OpenFeature dependency injection / hosting registration:Overloads exist for the default provider and for a domain-bound provider, each with and without an inline
Action<LaunchDarklyProviderOptions>(so options can also be bound from configuration).LaunchDarklyProviderOptionsexposesSdkKeyplusConfigureSdk, a hook ontoConfigurationBuilder, rather than re-declaring the SDK's configuration surface.The registration is in a separate package so that consumers of
LaunchDarkly.OpenFeature.ServerProviderwho do not use DI gain no new dependencies.dotnet packconfirms the provider package's dependency groups are unchanged (still onlyLaunchDarkly.ServerSdkandOpenFeature), andMicrosoft.Extensions.*arrives only transitively throughOpenFeature.Hostingin the new package.Two behaviors worth noting for review:
OpenFeature.Hostingregisters providers as transient, and each LaunchDarkly provider constructs anLdClientwith its own connection to LaunchDarkly. The internalProviderRegistrytherefore holds one provider — and thus one client — per domain, so resolvingFeatureProvidermore than once cannot open additional connections. The upstream flagd and OFREP providers construct a provider per resolution instead; that is cheap for them, and not for us.ILdClientused by each provider is registered too (keyed by domain for domain-bound providers), so migration flags and track events remain reachable. It is shut down along with the provider when the host stops.The new package is versioned and released in lockstep with the provider: the version marker is in
release-please-config.jsonextra-files, and the release build and publish actions build and pack both projects.Describe alternatives you've considered
LaunchDarkly.OpenFeature.ServerProvider, as the upstream flagd and OFREP providers do. Rejected because it putsOpenFeature.Hostingand theMicrosoft.Extensions.*closure in every consumer's dependency graph.PrivateAssets="all"to keep them out of the nuspec. Rejected: they are needed at runtime, so this only moves the failure to the consumer..DependencyInjectionafter the deprecated upstream package..Hostingmatches where the functionality now lives upstream.Additional context
OpenFeature.Hostingis still described upstream as experimental, and since 2.14.0 the DI integration uses an isolatedApiinstance rather thanApi.Instance— so a provider registered through DI is not visible to code evaluating flags through the global singleton. This is documented in the README; the minimumOpenFeature.Hostingversion is 2.14.0 so that behavior is consistent.How to test:
dotnet test(77 tests: 72 existing, 5 new). To check dependency isolation,dotnet packboth projects and inspect the.nuspecdependency groups.Link to Devin session: https://app.devin.ai/sessions/e52b5c9dfeec452cbfe1e8b8b8506c34
Requested by: @kinyoklion