RESTful service layer with MVC

  softwareengineering

I need a advice on creating an architecture where I want API layer in between UI layer and business layer. UI layer should only consume REST services for displaying data.

Reason for doing this is that we need to expose same service for others clients like iPad, Android etc.

Now my questions are:

  1. Do we need dependency injection in this case? (I don’t think so because we are not going to use any reference at UI layer. The only thing is, we are manipulating the JSON returned by service.)

  2. Will it hurt performance?

  3. Is this the right approach?

Do we need dependency injection in this case?

It depends on what you try to accomplish. Dependency injection is needed in order to easily replace the underlying implementation. Common examples are:

  • To replace actual implementation by stubs/mocks in a context of unit testing.

  • To easily swap between several data access layers (for instance to deal with several database systems).

In your case, you would probably want to test your presentation layer without having to do the actual calls to the API, in which case DI would be useful.

Will it hurt performance?

Any additional abstraction or layer hurts performance.

What you should ask yourself is:

  • Do you actually have performance issues?

  • If yes, what profiling reveals about the source of the slowness?

Don’t guess. Measure.

Is this the right approach?

Having a common API which is then used at once by desktop applications, mobile applications and web applications is a common practice and makes it possible to reduce code duplication and simplify the porting of a system to the different types of devices.

LEAVE A COMMENT