0

The scenario is to have a Mobile App and Web App too.

So currently I can think of two scenarios

enter image description here

Which one do you guys think is better?

PS : If needed I can also implement DAL Layer in both the cases in between DB and Business Layer.

Edit 1 : I must mention here that, the functionality of the Mobile App is identical to that of the Web App. Actually the Mobile App is intended to expose few of the functionalities so that user can use the software on the go.

Edit 2 : Architectural wise, I prefer the first one, because the Mobile App will be a Hybrid Mobile App. So whatever I'll develop for the web, I can compile the same thing in Cordova and publish with minimal changes for the native device specific api (such as Camera).

2
  • It Depends™. Is the functionality of the MVC Web App identical to that of the Mobile App?
    – Mast
    Jul 7, 2016 at 9:09
  • Actually the mobile app will expose few of the functionality that are available in Web App. But yes, everything is identical. Jul 7, 2016 at 10:00

1 Answer 1

1

I would go this way:

enter image description here

This uses a service to expose all of the bussiness functionality. Then, your MVC app could grab all the data returned from a service a create a View with it, while the API would use the same service to return JSON/XML.

Your MVC app and you API would then have the same funcionality and you mobile app could grab whatever info is needed from the API.

This avoids code duplication and is in my opinion a good way to structure your code, also, there's the benefit that your web app will not have to do calls to your API and performance will be better.

5
  • So you mean to create a WCF Service which would be consumed by MVC Web App and WebAPI to expose the same thing just via JSON/XML? So I just need the WebAPI to convert WCF Serialized Data to JSON / XML? Jul 7, 2016 at 10:45
  • Exactly, API consumes the service and returns JSON/XML (it should NOT do any business logic), You're web app (it should also NOT do any business logic) then consumes the same service but instead of JSON it returns your actual HTML.
    – Borjante
    Jul 7, 2016 at 10:51
  • Got it. Thanks a lot. But one question, WCF itself can process JSON / XML so why am I adding an layer (WebAPI) here just to convert the serialized data to XML / JSON? Jul 7, 2016 at 12:00
  • Because your API has the job of returning data and you MVC app should directly render it onto the page. You don't want to have an IF statement inside you MVC app controller to check if you have to send response as JSON or as a View. Also, your API with have diferent authentication mechanism than your MVC app
    – Borjante
    Jul 7, 2016 at 12:04
  • Glad it helped, if it did, you can upvote and validate the answer
    – Borjante
    Jul 7, 2016 at 12:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.