{"id":13629457,"url":"https://github.com/cloud0259/ControllerGenerator","last_synced_at":"2025-04-17T09:33:58.958Z","repository":{"id":181863485,"uuid":"667568018","full_name":"cloud0259/ControllerGenerator","owner":"cloud0259","description":"Automatic Controller Generator with Source Generator.","archived":false,"fork":false,"pushed_at":"2023-07-29T11:19:30.000Z","size":54,"stargazers_count":8,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-31T20:15:30.082Z","etag":null,"topics":["api","controller","csharp","sourcegenerator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloud0259.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-17T20:05:12.000Z","updated_at":"2023-11-20T12:36:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"c11acb86-82a4-4996-9582-5ef017903ac1","html_url":"https://github.com/cloud0259/ControllerGenerator","commit_stats":null,"previous_names":["cloud0259/controllergenerator"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud0259%2FControllerGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud0259%2FControllerGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud0259%2FControllerGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud0259%2FControllerGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloud0259","download_url":"https://codeload.github.com/cloud0259/ControllerGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751136,"owners_count":17196579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","controller","csharp","sourcegenerator"],"created_at":"2024-08-01T22:01:11.224Z","updated_at":"2024-11-08T20:30:59.328Z","avatar_url":"https://github.com/cloud0259.png","language":"C#","readme":"# ControllerGenerator\n| ControllerGenerator | ControllerGenerator.Abstraction | Action |\n|------------------|------------------|------------------|\n| [![NuGet](https://img.shields.io/nuget/v/ControllerGenerator?label=ControllerGenerator)](https://www.nuget.org/packages/ControllerGenerator)       | [![NuGet](https://img.shields.io/nuget/v/ControllerGenerator.Abstraction?label=ControllerGenerator.Abstraction)](https://www.nuget.org/packages/ControllerGenerator.Abstraction)         | [![Mon Badge](https://github.com/cloud0259/ControllerGenerator/workflows/.build/badge.svg)](https://github.com/cloud0259/ControllerGenerator/actions)         |\n| ![Nuget](https://img.shields.io/nuget/dt/ControllerGenerator?label=ControllerGenerator)         | ![Nuget](https://img.shields.io/nuget/dt/ControllerGenerator.Abstraction?label=ControllerGenerator.Abstraction)         |          |\n\n\nThis project is an automatic controller generator for .NET projects. It uses Source Generator to automatically create controllers from specified services in a project containing the services.\n\n## Installation\nTo use this generator, you need to install the ControllerGenerator.Abstractions library in the project that contains the services you want to use for generating controllers.\n\n```\nInstall-Package ControllerGenerator.Abstractions\n```\nIn your web project, it is necessary to install the ControllerGenerator library\n```\nInstall-Package ControllerGenerator\n```\n\n## Usage\nTo have your services recognized by the generator, each service or its interface must inherit the IAutoGenerateController interface.\n\n```csharp\npublic interface IMyService : IAutoGenerateController\n{\n    // Service methods\n}\n```\n## Request Generation based on Method Prefixes\n\nRequests in the generated controllers are determined based on the method prefixes:\n\n- If the service method starts with \"Get\", \"Post\", \"Patch\", \"Update\", \"Create\", or \"Delete\", the generated request will correspond to the respective HTTP methods.\n- If there is no prefix, the generated request will be of type HTTP POST.\n\nAttributes can be used in services. These will be recognized by the Source Generator\n\n## Requirements\nThe Source Generator library must be installed in the target project. The target project should be a .NET 7.0 web application or a higher version.\n\n### Example\nHere's an example of using this generator:\n\n```csharp\n// In the project containing the services\n\npublic interface IMyService : IAutoGenerateController\n{\n    Task\u003cUser\u003e GetUserAsync(int id);\n    Task\u003cUser\u003e PostUser(UserData data);\n    Task UpdateUser(int id, UserData data);\n    // Other service methods\n}\n\n//Service implementation\npublic class MyService : IMyService\n{\n    //Property, Ctor ....\n    \n    [HttpGet] //it's not mandatory\n    [Authorize(\"Admin\")]\n    public async Task\u003cUser\u003e GetUserAsync(int id)\n    {\n        return await userList.FirstOrDefaultAsync(x =\u003e x.Id == id);\n    }\n\n    [NoGenerated] //This method is not generate for the controller\n    public Task\u003cUser\u003e PostUser(UserData data)\n    {\n        throw new Exception(\"An error has occured\")\n    }\n\n    //Other method...\n}\n\n// In the .NET 7.0 or higher web project\n\n// The generator will automatically create a controller for IMyService with corresponding HTTP methods for each method in the service.\npublic class MyController : ControllerBase\n{\n    private readonly IMyService _myService;\n\n    public MyController(IMyService myService)\n    {\n        _myService = myService;\n    }\n\n    // GET endpoint generated for GetUserAsync\n    [HttpGet(\"{id}\")]\n    public IActionResult GetUser(int id)\n    {\n        // Implementation\n    }\n\n    // POST endpoint generated for PostUser\n    [HttpPost]\n    public IActionResult PostUser([FromBody] UserData data)\n    {\n        // Implementation\n    }\n\n    // Other endpoints for UpdateUser and other service methods\n}\n```\n\nIt is possible to replace a controller generated by the source generator by creating a controller that inherits the interface of the service to replace\n\n```csharp\npublic class MyController : ControllerBase, IMyService\n{\n    //Implement the interface to replace the self-generated controller\n}\n```\n\n## Disclaimer\nThis generator uses Source Generator to automatically generate controllers. Make sure you understand how it works before using it in your project. Please perform thorough testing to ensure that the generated controllers meet your requirements.\n\n## Contributing\nContributions are welcome! Please see the CONTRIBUTING.md file for information on how to contribute to this project.\n\n## License\nThis project is licensed under the MIT License.\n","funding_links":[],"categories":["Contributors Welcome for those","Source Generators"],"sub_categories":["1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category","Webprogramming"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud0259%2FControllerGenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloud0259%2FControllerGenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud0259%2FControllerGenerator/lists"}