GithubHelp home page GithubHelp logo

bubdm / commandr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codinggorilla/commandr

0.0 0.0 0.0 31 KB

Allows routing of ASP.NET endpoints directly to commands, eliminating MVC Controllers entirely.

License: MIT License

C# 100.00%

commandr's Introduction

commandr

WARNING: This project is still highly experimental, use at your own risk

What is commandr

For year we have been using the outdated notion of controllers in ASP.NET to build our web APIs. However, the controller itself doesn't serve much of a purpose, other than to group together a bunch of methods that maybe share some bits of routing information. Recently, the mediator pattern has caught on, causing us to write a lot of boilerplate code like:

public class MyController : ApiController
{
    private readonly ICommandBus _commandBus;

    public MyController(ICommandBus commandBus)
    {
        _commandBus = commandBus;
    }

    [HttpGet("/something/{id}")]
    public IActionResult GetSomethingApi(int id)
    {
        var command = new GetSomethingCommand { Id = id };
        return _commandBus.Invoke(command);
    }
}

Assuming your API has more than one endpoint/command, that's a lot of boilerplate code just to fire off commands and return the result. Commandr aims to solve that problem by extending ASP.NET Core's endpoint routing feature to bind directly to a command, and then execute the command for you. No more controllers, ever.

The result is a project that is smaller, cleaner, and in my opinion a lot easier to test because you can simply write unit tests for your command handlers and not worry about creating controllers and all the ceremony therein.

I've been a fan of Jasper, and I have produced a simple example that ends up being very little code compared to a similar project using MVC controllers. Commandr, however, aims to be agnostic as to which of the messaging/command stacks you choose. Commandr could just as easily work with Mediatr, or you could even write your own simple executor if you want.

As stated above, Commandr is in it's infancy, so there's still a lot of work to do. The ultimate goal is for it to be a drop-in replacement for ASP.NET MVC for web APIs (it will never try to replace Razor/Blazor).

Would love to hear your thoughts and ideas!

commandr's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.