Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

Implements type-safe entity invocation using interface-based proxies, eliminating string-based operation names and enabling compile-time checking. Uses System.Reflection.DispatchProxy to avoid external dependencies.

Changes

  • Core API: Added IEntityProxy marker interface and CreateProxy<T>() extension methods for TaskOrchestrationEntityFeature and DurableEntityClient
  • Proxy implementation: Uses DispatchProxy to dynamically implement interfaces at runtime, routing method calls to SignalEntityAsync or CallEntityAsync based on return type
  • Method mapping:
    • void → SignalEntityAsync (fire-and-forget)
    • Task → SignalEntityAsync (client) or CallEntityAsync (orchestration)
    • Task<T> → CallEntityAsync (orchestration only, throws for client)
  • Tests: 14 unit tests covering orchestration and client scenarios
  • Sample: ShoppingCart entity demonstrating usage patterns

Usage

// Define entity operations as interface
public interface ICounterProxy : IEntityProxy
{
    Task<int> Add(int value);
    Task<int> Get();
    void Reset();  // Fire-and-forget
}

// In orchestration - supports awaiting results
var counter = context.Entities.CreateProxy<ICounterProxy>(entityId);
int result = await counter.Add(5);

// From client - fire-and-forget only
var counter = client.Entities.CreateProxy<ICounterProxy>(entityId);
counter.Reset();

Design Notes

Client proxies only support fire-and-forget operations since clients lack orchestration context for waiting on entity results. Separate interfaces recommended for client vs orchestration usage when operations return values.

Original prompt

This section details on the original issue you should resolve

<issue_title>Support strongly typed entity invocation</issue_title>
<issue_description>This issue tracks the discussion and design for adding a strongly typed pattern for entity invocation. For in-proc durable functions, entities can be strongly invoked via dynamic proxies. This is an option for dotnet isolated, however, we should implement it without using 3rd party libraries (keep our dependencies minimal). An alternative would be to perform this via a source generator. But we should not limit the discussion to only proxies and also evaluate alternatives (such as mediator pattern #73).

TODO: flush out options, requirements</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Implement strongly typed entity invocation design Add strongly-typed entity invocation via DispatchProxy Jan 5, 2026
Copilot AI requested a review from YunchuWang January 5, 2026 22:26
@torosent
Copy link
Member

torosent commented Jan 6, 2026

@copilot What is the performance overhead System.Reflection.DispatchProxy will have in this implementation? can we use other techniques?

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.

Support strongly typed entity invocation

3 participants