Skip to content

Make 'HttpResponseContext' not needed in PS function script #113

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

Merged
merged 3 commits into from
Dec 11, 2018
Merged

Conversation

daxian-dbw
Copy link
Contributor

@daxian-dbw daxian-dbw commented Dec 9, 2018

Make HttpResponseContext not needed in PS function script.

To properly convert a value for a specific output binding name implicitly, we need to know the metadata of the binding referred by that name, such as the type of the output binding.
The changes in this PR register the output binding metadata to a concurrent dictionary with the Runspace's InstanceId as the key before start running a function script, and then un-register after the function script finishes running. When a function script that calls Push-OutputBinding is running, we can figure out the current Runspace by Runspace.DefaultRunspace, and then we can query for the output binding metadata by using the InstanceId.

This approach take into the concurrency support that we will have in future. Push-OutputBinding is able to get the metadata about the function script that is running even with multiple Runspaces/PowerShellManagers processing requests at the same time.

Fix #93

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM - a couple nits.

I was wondering if we could hold off on coupling the FunctionLoader and the PowerShellManager just to keep the separation of concerns but I can't think of a way to keep it that way.

@TylerLeonhardt
Copy link
Member

Looks like there's a CI failure. I think you missed including the Resources file?

@daxian-dbw
Copy link
Contributor Author

It turns out the .gitignore cause the resource.psd1 file to be ignored.

@daxian-dbw
Copy link
Contributor Author

I was wondering if we could hold off on coupling the FunctionLoader and the PowerShellManager just to keep the separation of concerns but I can't think of a way to keep it that way.

@TylerLeonhardt and I chatted about this offline. This PR doesn't introduce coupling between FunctionLoader and PowerShellManager. FunctionMetadata serves as a store that holds the function metadata information for the function script that is running in each Runspace (query key is the Runspace's InstanceId). The function metadata is registered before a PowerShellManager runs the corresponding function script, and is unregistered after the corresponding function script is done running.

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