mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
HandlebarsRegistrationCallback not fired #258
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jantanis on GitHub (Mar 2, 2020).
WireMock.Handlebars.zip
See attached reproduction project. Start and go to http://localhost:5001/datasets
HandlebarsRegistrationCallback is not fired, so I can't register custom handlebar extensions.
@StefH commented on GitHub (Mar 2, 2020):
This is because you already use the
WithCallback()in the response, and this means that the "UseTransformer" is not called anymore, and also the HandlebarsRegistrationCallback is not done anymore. (This is current behavior in de the code.)@jantanis commented on GitHub (Mar 2, 2020):
Does this mean that you cannot use Handlebars if you use WithCallback()? If so I would really like this as a feature.
@StefH commented on GitHub (Mar 2, 2020):
I see your point.
You want to use code like this?
@jantanis commented on GitHub (Mar 2, 2020):
Yes. Now I've implemented Handlebars myself in the callback function, but I'm missing the Wiremock handlebar extensions. If only I have access to the handlebars context (IHandebars) of Wiremock I'm good to go. Right now there is no way for me to achieve this.
@StefH commented on GitHub (Mar 2, 2020):
I've made a preview fix (can be found via MyGet) :
WireMock.Net.1.1.9-ci-12788. This one should fire the HandlebarsRegistrationCallback.@jantanis commented on GitHub (Mar 3, 2020):
Yes, that works. But is it not possible to expose the IHandlebars on the WireMockServer? I require that context somewhere else too. As I see it every request registers the handlebars again, that isn't really necessary right?
@StefH commented on GitHub (Mar 3, 2020):
Correct, the factory only needs to be created once, no need to create that for every response. I'll check if that's easy to change.
And where do you need that IHandlebars ? Would it help if this was maybe available in callback?
@jantanis commented on GitHub (Mar 3, 2020):
I managed to complete what I wanted by assigning the IHandlebars in the callback to a static property. I can now use this property wherever I want. I think the best way to do this is to init IHandlebars using the factory on startup and then expose it for everything to use. Now you have to await 1 transform cycle to have it working.
@StefH commented on GitHub (Mar 4, 2020):
I'm looking into the code to do some changes, but the HandlebarsRegistrationCallback is still fired with each response because every response gets a fresh handlebars-context. I'm not sure if I can change this.
For now, I'll just fix your bug that the HandlebarsRegistrationCallback was never fired when using
WithCallbackYou can create a new issue with the specific issue, or try to make PR yourself.
Linking https://github.com/WireMock-Net/WireMock.Net/pull/435 ...
@StefH commented on GitHub (Mar 5, 2020):
closing...