2

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?

Arseni Mourzenko
138k32 gold badges355 silver badges540 bronze badges
asked Oct 12, 2015 at 5:36

1 Answer 1

5

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.

answered Oct 12, 2015 at 6:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.