asp.netrestasp.net-web-apimvp

How to transform Model-View-Presenter architecture to WebAPI?


Right now we are working with a classic ASP.NET WebForms project with a Model-View-Presenter (MVP) architecture. Our company wants to move towards a common way to share data between applications based on RESTful APIs. Therefore, we are looking for ways to transform our MVP architecture to a WebAPI project. There is quite a lot of code in the presenters and it will take a long time to move the code to another layer. We are looking for a good way to transform to an architecture based on WebAPI's.

Right now there is a strong binding between the .aspx pages with code behind and the presenter layer. One idea is to place one more layer in between the Presenter and View. That way we can replace the old .aspx with a more modern page. E.g.,

         Model
       Presenter
Old view | WebAPI layer
                New view

Is this a good idea? We hope to hear your inputs regarding this plan. What are the pitfalls? Are there better ideas? Are there experiences learned from any similar scenario to this?


Solution

  • The problem is that a Presenter, or Supervising Controller doesn't map well into the REST model, because they have both state and actions associated with them.

    A WebAPI layer is actually going to map much more closely with your repository layer than it will your presenter.

    The Presenter, instead of existing on the server, would exist on the client.

    My advice is not to go down this path of trying to mix the two together like this. There will always be an enormous impedance mismatch, and you will end up with an API that isn't very useful to other clients. Especially if you want to move to more modern Mobile/Web application architectures.