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

Customizing RefitStubs.g.cs generatation #499

Closed
matheusneder opened this issue Jun 4, 2018 · 6 comments
Closed

Customizing RefitStubs.g.cs generatation #499

matheusneder opened this issue Jun 4, 2018 · 6 comments

Comments

@matheusneder
Copy link

I didn't find a way to customize RefitStubs.g.cs generatation with out editing mustache template in the Refit package.

I'd like to propose a change to InterfaceStubGenerator.ExtractTemplateSource: It'll try get "GeneratedInterfaceStubTemplate.mustache" file from the project directory, if doesn't exists, get it from package directory or embbeded resource just as it is.

This will bring the ability to the user customize RefitStubs.g.cs generatation for a single project scope.

What do you think about? Is there another way already done in Refit to get this kind of customization?

@bennor
Copy link
Contributor

bennor commented Jun 4, 2018

Why do you need to customise it? And what are you planning on doing?

@onovotny recently merged a change that makes the generated classes partial, allowing for some customisation.

@matheusneder
Copy link
Author

matheusneder commented Jun 4, 2018

At first I'd like to throw customized exception types insteadof ApiException in case of HTTP status not 2xx. The exception to be thrown will depends os response body, so I wish to put some logic to the method body.

@clairernovotny
Copy link
Member

One concern here is that any external customizations to the template could be fairly brittle. The template today depends heavily on the internal implementation of the request builder. A PR like #494 changes the template significantly as part of the feature work.

We don't have any current plans to formalize the contract since it is an implementation detail at this point to support AOT platforms. Otherwise, we'd have used dynamic ways to create the impls.

@matheusneder
Copy link
Author

I understood, thanks for feeback.

I'm planning to use Refit in my projects which are most of all aspnet core microservices. As I commented, I'd like to make my clients throwing it's own exception types insteadof ApiException. To handle this, at first, I'll use a dynamic proxy (based on System.Reflection.DispatchProxy), so unfortunatelly, it will not support AOT platforms.

Would you consider provide a way (on the generated client) to intercept the call? Should be events, something like OnBeforeCall, OnException, OnAfterCall. What do you think about?

@clairernovotny
Copy link
Member

Closing due to age. Please try Refit v6 and reopen if still an issue.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants