HandlebarsRegistrationCallback not fired #258

Closed
opened 2025-12-29 15:19:10 +01:00 by adam · 10 comments
Owner

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.

Originally created by @jantanis on GitHub (Mar 2, 2020). [WireMock.Handlebars.zip](https://github.com/WireMock-Net/WireMock.Net/files/4274322/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.
adam added the feature label 2025-12-29 15:19:10 +01:00
adam closed this issue 2025-12-29 15:19:10 +01:00
Author
Owner

@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.)

@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.)
Author
Owner

@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.

@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.
Author
Owner

@StefH commented on GitHub (Mar 2, 2020):

I see your point.

You want to use code like this?

private static ResponseMessage DataSetCallback(RequestMessage arg)
{
	return new ResponseMessage
	{
        BodyData = new BodyData
        {
            BodyAsJson = new
            {
                Test = "test: {{request.url}}"
            }
        },
		StatusCode = 200
	};
}
@StefH commented on GitHub (Mar 2, 2020): I see your point. You want to use code like this? ``` c# private static ResponseMessage DataSetCallback(RequestMessage arg) { return new ResponseMessage { BodyData = new BodyData { BodyAsJson = new { Test = "test: {{request.url}}" } }, StatusCode = 200 }; } ```
Author
Owner

@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.

@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.
Author
Owner

@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.

@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.
Author
Owner

@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?

@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?
Author
Owner

@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?

@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?
Author
Owner

@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.

@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.
Author
Owner

@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 WithCallback

You 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 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 `WithCallback` You 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 ...
Author
Owner

@StefH commented on GitHub (Mar 5, 2020):

closing...

@StefH commented on GitHub (Mar 5, 2020): closing...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#258