Amit Soni
Amit Soni

Reputation: 3316

Restful service layer with MVC

I need a advice on creating a 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 question is:-

1) Do we need dependence inject in this case? (i don't think so coz we are not going to use any reference at UI layer. The only thing is, we are manipulating the JSON returning by service.)

2) Will it hurt performance?

3) Is this the right approach?

Any help will be appreciated. Thanks

Upvotes: 1

Views: 1112

Answers (3)

Choco Smith
Choco Smith

Reputation: 1668

we're doing roughly the same thing now.

1) No, you can't.

2) No, twitter is api first, they seem to be doing ok. I guess technically it will, but it does mean you can scale horizontally so the extra hop overhead can easily be counteracted.

3) You have multiple ui clients so it seems like a decent viable solution.

Security Security: Basic Authentication Its the easiest to setup, but be aware the token is reversible, so use HTTPS to encrypt the communication. The HTTP Authorization header containing the username and password is sent with every request to the api level.

You could use session but that requires a bit more setup.

There are plenty of how to's on setting up basic authenication in C# and web api.

Upvotes: 1

ekostadinov
ekostadinov

Reputation: 6950

In my experience I've seen such platform oriented approach - providing mSOA to N amount of clients. The architectural solution was a Facade that was hiding all the complex Business Layer requests and in the same time providing UI insensitive processing.

Will it hurt performance?

Not necessary - since it has knowledge of how to handle all required sub-systems requests. All the clients just know that they need a single JSON contract to get the job done, not which and how many of the services to call. By doing so - we have a much better and simplified communication. Take a look at the Mediation (intra-communication) pattern:

Mediator

Upvotes: 1

blogbydev
blogbydev

Reputation: 1495

The way i created an API for me was:

  • Project 1 : WebAPI serving as a portal to fetch data
  • Project 2 : Class Library, providing services to the WebAPI layer.
  • Project 3 : Class Library, providing data to my services layer using EF.

Now, different controllers in the web api project require different service objects(from project 2) to work with. I had to provide constructors for those controllers using DI. for this i used Autofac.

For you, your business layer would be Project 2.

Data flowing through one more Project layer might take some time, and you will need to put up exception handling and logging again in the API layer. i don't think performance should be big problem here.

Upvotes: 1

Related Questions