Skip to content

Further refine entity samples, add .http files and launch task#218

Merged
jviau merged 5 commits intomicrosoft:feature/entitiesfrom
jviau:update-samples
Oct 12, 2023
Merged

Further refine entity samples, add .http files and launch task#218
jviau merged 5 commits intomicrosoft:feature/entitiesfrom
jviau:update-samples

Conversation

@jviau
Copy link
Member

@jviau jviau commented Oct 12, 2023

  1. Addresses feedback from previous samples PR
  2. Adds more HTTP endpoints for counter and lifetime examples
  3. Adds .http files to show quick ways to call these examples.
  4. Adds launch.json and tasks.json for running this sample in vscode

/// Optional property to override. When 'true', this will allow dispatching of operations to the <see cref="State">
/// object if there is no matching method on the entity. Default is 'false'.
/// Stated differently: if this is <c>true</c> and there is no matching method for a given operation on the entity
/// type, then the operation will attempt to find a matching method on <typeparamref name="TState"/> instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised to see this as a feature since I don't recall it ever being discussed. What are the use-cases? I'm also interested to understand the lifetime implications, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to help migration so customers don't have to derive from ITaskEntity if they do not want to.

What lifetime implications are you concerned about?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what happens if the state object is null, etc. I don't recall any such feature existing for the in-proc model. But maybe I'm misunderstanding what is being referred to by TState? Is that not the entity state?

Copy link
Member Author

@jviau jviau Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In proc model does not have a concept of ITaskEntity base class. This is here to align closer with how inproc behaves: you can dispatch entity operations to some POCO. We have designed it so that POCO dispatching is done through the TState here.

If state is null we will use Activator.CreateInstance.

Copy link
Member

@sebastianburckhardt sebastianburckhardt Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to summarize the discussions and design a bit:

For in-proc we had two models:

  • class-based. Entity state must be defined by a class, and operations are dispatched to methods.
  • function-based. Very low level but totally customizable, with entity state being an arbitrary type.

For isolated we have three (but only the first two are expected to be widely used):

  • class-based. Pretty much the same as for in-proc.
  • TaskEntity<TState>. Similar to class-based but with one layer of indirection, which allows advanced scenarios (arbitrary TState types, dependency injection, customizable code for constructing the state) without having to give up the convenience of the class-based approach.
  • ITaskEntity. Very similar to function-based. Very general but verbose. Not recommended unless you are building some kind of framework on top of entities.

@jviau jviau requested a review from cgillum October 12, 2023 21:08
@jviau jviau merged commit 56c012c into microsoft:feature/entities Oct 12, 2023
@jviau jviau deleted the update-samples branch October 12, 2023 23:01
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.

3 participants