Skip to content
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

CustomUriFunctions should not be static or irreversible #821

Closed
robward-ms opened this issue May 30, 2017 · 2 comments
Closed

CustomUriFunctions should not be static or irreversible #821

robward-ms opened this issue May 30, 2017 · 2 comments
Labels

Comments

@robward-ms
Copy link
Contributor

CustomUriFunctions is a static class. Registering a function with it by calling AddCustomUriFunction is irreversible. This is a problem for unit testing and object lifecycle in the application itself.

Assemblies affected

Microsoft.OData.Core, Version=7.0.0.0

Reproduce steps

Register a custom function.

Expected result

ODataUriParser can be created with and without the custom functions regardless of global state.

Actual result

CustomUriFunctions.AddCustomUriFunction(...) is the way to register custom functions. ODataUriParser uses CustomUriFunctions to look up signatures, so it's not possible to supply it with a list independent of other instances of ODataUriParser. It's not possible to unregister a function once it's registered, either.

Additional details

In addition, CustomUriFunctions.AddCustomUriFunction(...) can only be called once with the same signature, otherwise it throws an exception with the CustomUriFunctions_AddCustomUriFunction_CustomFunctionOverloadExists error message.

Why is this necessary? Even checking the built-in functions - what is the harm of registering the same signature twice? The implementation is not part of the registration, so this error handling seems counterproductive. It forces the user to lock and check to make sure registration hasn't already happened before calling AddCustomUriFunction.

This wouldn't be an issue if registration was not at a global/class level but at an instance level.

Copied from: OData/WebApi#949

@2BitSalute
Copy link

I meant to give it a try myself, but haven't found the time so far.

@habbes
Copy link
Contributor

habbes commented Jun 28, 2022

Closing this due to inactivity. If this issue still affects the latest version of the library, kindly open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants