Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !1937

[REQ][Asp.Net Core] Overrightable csproj for controllers and models

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/aaronclong/generate-overwriteable-csproj into master Jan 17, 2019
  • Overview 0
  • Commits 5
  • Pipelines 0
  • Changes 19

Created by: aaronclong

The current Asp.Net Core server generator doesn’t allow for iterative server stub generation. Users are forced to generate a full solution, and despite the template modification and ignore, it still doesn’t provide a truly modular and automated solution for iterative development. Often additive changes to APIs require both clients and servers to be updated, but the current Asp.Net approach doesn’t emphasize this. We are left with modifying generated source code and manually copy/pasting changes in an error prone process.

It would be far more practical to simple generate a csproj with the models and controllers that another project would then reference. The actual core business logic could be IOCed via an interface into the generated controllers. It becomes the developer’s responsibility to actually implement the interface, which the generated code would invoke.

It would look similar to this:

public interface IPetControllerLogic 
{
	IList<string> GetPetList();
}

[Route("…")]
public class PetController
{
    public PetController(IPetControllerLogic controllerLogic)
    {		….
    }


    [HttpGet]
    [ProducesResponseType(typeof(IList<string>), 200)]
    [ProducesResponseType(500)]
    public IList<string> GetPets()
    {
        return this.contollerLogic.GetPetList();
    }
}

It would provide greater convenience because we could regenerate our API with spec changes and avoid overwriting business logic. The code generation process would be dramatically simplified.

The downside to this approach would be some caveats in Asp.Net Core’s design. Namely MVC pulls in all controllers in referenced dlls. The consumer of this dll would automatically opt into all the controllers, and there are many cases where this functionally wouldn’t be ideal. In that case, there would need to be a config toggle to make the controller abstract. In doing so, the consumer would need to subclass it for it to be instantiated. It also affords the consumer the ability to provide extra attributes if needed.

I would like to propose a new Asp.net Core option or a separate command to do this.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/aaronclong/generate-overwriteable-csproj