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

Supply lazy TemplateEngine, HttpClientFactory, and DefaultHttpClient. #2564

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

kyle-winkelman
Copy link
Contributor

@kyle-winkelman kyle-winkelman commented Jan 9, 2024

Draft for issue in which ExtensionFactories are supplied a null TemplateEngine, HttpClientFactory, and DefaultHttpClient from Extensions.

References

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

@kyle-winkelman kyle-winkelman requested a review from a team as a code owner January 9, 2024 16:52
@kyle-winkelman kyle-winkelman marked this pull request as draft January 9, 2024 16:52
@tomakehurst
Copy link
Member

This sort of thing is a shortcoming of not having full DI (which I briefly tried by decided against the added complexity).

The approach we're intending to promote to solve this is the Lazy class e.g. https://github.com/wiremock/wiremock/blob/master/src/main/java/org/wiremock/webhooks/Webhooks.java#L44

@kyle-winkelman kyle-winkelman changed the title Properly initialize TemplateEngine in Extensions. Supply lazy TemplateEngine, HttpClientFactory, and DefaultHttpClient. Jan 15, 2024
@kyle-winkelman
Copy link
Contributor Author

What do you think of supplying lazy implementations as the PR currently reflects?

Do you know much about backwards compatibility? Because I contemplated turning TemplateEngine into an interface to make it easier to extend, but was unsure if that would maintain compatibility.

@kyle-winkelman kyle-winkelman marked this pull request as ready for review January 15, 2024 16:58
@tomakehurst
Copy link
Member

Hmmmm...I hadn't thought of doing this way but I like it, I think...

@kyle-winkelman
Copy link
Contributor Author

Haha I have a similar sentiment. I don't love this approach, but I can't think of a better way. Maybe explicitly creating classes named LazyTemplateEngine, LazyHttpClientFactory, and LazyHttpClient would help make it more clear?

Alternatively, we extensively document in Extending WireMock via custom code the limitations of using these methods.

@tomakehurst
Copy link
Member

Yeah, I think creating top-level classes in the way you described would clarify things a bit.

How about we do that, then I'll merge it?

@kyle-winkelman
Copy link
Contributor Author

Done!

@tomakehurst tomakehurst merged commit 0356152 into wiremock:master Jan 24, 2024
7 checks passed
@kyle-winkelman kyle-winkelman deleted the templateEngine branch March 6, 2024 14:40
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.

Extensions always supplies a null TemplateEngine to ExtensionFactory
2 participants