Replies: 1 comment
-
Hi @j2jensen, Thanks for reaching out. After reviewing the links you shared, it does seem like we have some pending work to update our guidance here and frankly I'm also a bit confused on the best practices :-) . @sebastianburckhardt: any chance you chime in here with some advice? I also see this old PR attempted to update our guidance but got closed prematurely: https://github.com/MicrosoftDocs/azure-docs-pr/pull/165981 @sebastianburckhardt: was this docs PR close to completion? Does it make sense to re-open it and wrap it up? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The docs encourage the use of this pattern to do custom initialization of a property prior to calling
DispatchAsync
.This issue indicates the problem with that approach: the object we pass in must be the entity instance itself. In experimenting it appears that calling
DispatchAsync
after callingSetState
causesDispatchAsync
to use the same instance of the entity that we passed in. That means we miss out on the Dependency Injection thatDispatchAsync
would normally perform.This comment clarifies:
That seems to directly contradict the pattern mentioned earlier. That same comment goes on to recommend passing the context itself into
DispatchAsync
and injecting it in the entity's constructor:However, this comment points out that the static
Run
method is skipped entirely when someone callsclient.ReadEntityStateAsync
.So calling
ReadEntityStateAsync
would cause the previous example to throw a null reference exception, because anull
value would be passed into thectx
parameter. The same would be true if we just usedEntity.Current
instead of an injected context: that property isnull
when callingReadEntityStateAsync
.So it seems like all the recommended patterns break in one of the following cases:
client.ReadEntityStateAsync
)Are there recommended patterns that enable all of these cases to work together? Are they documented anywhere?
Beta Was this translation helpful? Give feedback.
All reactions