-
Notifications
You must be signed in to change notification settings - Fork 44
Add New Property Properties
to TaskOrchestrationContext
#415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Properties
to TaskOrchestrationContext
throw new ArgumentNullException(nameof(properties)); | ||
} | ||
|
||
this.Properties = properties.ToDictionary(pair => pair.Key, pair => pair.Value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting from IEnumerable<KVP>
to a dictionary is dangerous because IEnumerable<KVP>
allows duplicate keys whereas dictionary does not. We should change the properties
parameter to be a dictionary instead of IEnumerable<KVP>
to avoid these kinds of problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is safe if you use a foreach
loop and set the key each time, so last key wins. My preference for IEnumerable is only to follow the "take in least derived, return most derived" principal. But I am not unmoving in that. If you disagree and want IDictionary, that is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Chris and Jacob. I updated this to be Dictionary. Because to write a foreach loop, I have to either grant Properties private set
, or adding a new field to store this and then pass the value to Properties. Just feel like using Dictionary directly here seems like a more straightforward and cleaner way in this case. Let me know if you prefer others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am okay with going back to dictionary, but I don't see why you need a private set
. The following is valid without any setter on Properties
:
this.Properties = new();
foreach ((string key, object? value) in properties)
{
this.Properties[key] = value;
}
or if this.Properties
is IReadOnlyDictionary<string, object?>
, then you can do this:
Dictionary<string, object?> props = new();
foreach ((string key, object? value) in properties)
{
props[key] = value;
}
this.Properties = props;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor nits
…oft/durabletask-dotnet into nytian/context-add-config
This PR adds a new property IDictionay<string, object?>
Properties
atTaskOrchestrationContext
, which allowsDurableTaskOptions
from WebJobs.Extensions.DurableTask can be passed throughMicrosoft.DurableTask.Protobuf.OrchestratorRequest
.Related PR: