AutoGeneratedSystem icon indicating copy to clipboard operation
AutoGeneratedSystem copied to clipboard

Allow Users to Extend Controller's Auto-Generated Code

Open pticostarica opened this issue 2 years ago • 0 comments

Sometimes developers would want to implement their own custom code like validations, before, and after the main logic of the method. We are looking for the best way to allow for this and currently have two ideas

  • Use partial methods, Source Code Generator would define the partial method, and the user's custom code will implement it, then the code generator could end up with something like this
[HttpPost("[action]")]
public async Task CreateApplicationUser(ApplicationUserModel ApplicationUserModel, CancellationToken cancellationToken)
{
  await BeforeCreateApplicationUser(ApplicationUserModel);
   // MAIN BODY
  await AFTERCreateApplicationUser(ApplicationUserModel);
}

This approach needs to be validated since there were some compilation issues when doing a POC

  • Interface-based validations: Create interfaces like IBeforeCreateApplicationUser and set it to the user's created class, then if the generator find these interfaces, add the matching code lines to each endpoint code.

Please feel free to add additional ideas on the best way to allow for developers to extend the functionality of the auto-generated endpoints methods.

pticostarica avatar Apr 19 '22 16:04 pticostarica