Skip to content

feat: add keyed Dataverse client registration - #9

Merged
LarsBauer merged 6 commits into
mainfrom
copilot/add-named-dataverse-client-registration
Jun 20, 2026
Merged

feat: add keyed Dataverse client registration#9
LarsBauer merged 6 commits into
mainfrom
copilot/add-named-dataverse-client-registration

Conversation

Copilot AI commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

This PR adds named Dataverse client registration on top of the existing AddDataverseClient() API using native keyed DI, enabling multiple independently configured clients (for example source/target) in the same app. The unnamed registration path remains unchanged and isolated from the named path.

  • API surface: named AddDataverseClient overloads

    • Added:
      • AddDataverseClient(string name, Action<DataverseClientOptions> configureOptions)
      • AddDataverseClient(string name, IConfiguration configuration)
    • Both configure named options and route through a dedicated named registration path.
  • DI wiring: separate keyed registration path

    • Added a separate private AddNamedDataverseClientCore(string name) in ServiceCollectionExtensions.
    • Registers:
      • keyed singleton ServiceClient
      • keyed scoped IOrganizationServiceAsync2 via Clone()
    • No reuse of the unnamed core path, preventing default-name collisions.
  • Factory support for named options

    • Added ServiceClientFactory.CreateNamed(IServiceProvider, string name).
    • Uses IOptionsMonitor<DataverseClientOptions>.Get(name) to resolve named options.
    • Keeps existing Create(IServiceProvider) unchanged.
  • Test coverage for named behavior

    • Added tests for:
      • keyed service registrations/lifetimes
      • named options binding (action + configuration)
      • chaining return contract
      • coexistence of named + unnamed registrations
      • coexistence of two named clients
      • named validation failures (missing URL / non-HTTPS)
      • ServiceClientFactory.CreateNamed behavior (default/custom credential, deferred connection)

Example usage:

services.AddDataverseClient("source", options =>
{
    options.OrganizationUrl = new Uri("https://source.crm4.dynamics.com");
    options.DeferConnection = true;
});

services.AddDataverseClient("target", configuration.GetSection("Dataverse:Target"));

// consumer
public sealed class Migrator(
    [FromKeyedServices("source")] IOrganizationServiceAsync2 source,
    [FromKeyedServices("target")] IOrganizationServiceAsync2 target)
{
}

Copilot AI changed the title [WIP] Add named Dataverse client registration to AddDataverseClient API feat: add named keyed Dataverse client registration Jun 20, 2026
Copilot AI requested a review from LarsBauer June 20, 2026 13:22
@LarsBauer LarsBauer changed the title feat: add named keyed Dataverse client registration feat: add keyed Dataverse client registration Jun 20, 2026
@LarsBauer
LarsBauer marked this pull request as ready for review June 20, 2026 14:01
@LarsBauer
LarsBauer merged commit 8f6e645 into main Jun 20, 2026
1 check passed
@LarsBauer
LarsBauer deleted the copilot/add-named-dataverse-client-registration branch June 20, 2026 14:02
This was referenced Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants