FairPlayTube icon indicating copy to clipboard operation
FairPlayTube copied to clipboard

Implement the Clients Service Generator

Open efonsecab opened this issue 3 years ago • 2 comments

Note: A branch with initial progress already exists: https://github.com/efonsecab/FairPlayTube/tree/ClientServicesGenerator

Important After doing some initial testing it seems the Source Generators projects only have access to the project being compiled and dependencies.

  • Create a new class library project named "FairPlayTube.Controllers.Interfaces"
  • Add an interface class for each controller, format: "I[ControllerName]" e.g.: IPlaylistController
  • Add the corresponding endpoints signatures to the respective interface

After doing that, reference the interfaces project from both "FairPlayTube.Controllers" and "FairPlayTube.ClientService", in theory, this will allow the Source Generator to have access to the interfaces, and with those signatures we can automatically generate the client classes.

We want to automatically generate some of the client services using C# Source Generators.

  • Create a class named "GenerateClientServiceAttribute" in the Controllers project, under a folder named "CustomAttributes"
  • Mark the PlaylistController with "[GenerateClientService]"
  • Create a new project named "FairPlayTube.Generators.ClientServices", with a class named "ClientServicesGenerator"
  • Reference the generator project from the "FairPlayTube.ClientServices" existent project

The "ClientServiceGenerator" class must implement "IIncrementalGenerator".

This class would search for all of the controllers marked the "[GenerateClientService]", inspect all of the endpoints and create a class named "{ControllerPrefix}ClientService" in a file with extension ".g.cs" under a folder named "Generated".

The class must contain all of the client methods to call the endpoint methods, using the existent pattern from the other client services.

efonsecab avatar Feb 05 '22 13:02 efonsecab

@LuisiitoDev , you can start it whenever you want, please let me know if you have any questions

efonsecab avatar Feb 17 '22 01:02 efonsecab

@efonsecab perfect, I will be starting the task.

LuisiitoDev avatar Feb 17 '22 14:02 LuisiitoDev