简体   繁体   中英

Web Api integration

I have an MVC 5 WebApi project that use account controller to manage user and resource. It's work fine.
Now I neet to add the same client functionality, ie with External App (iOS, Android, Windows Phone). For this porpuse, I think to use WebApi. What is best practice to add WebApi to my project? I need to use AccountUser to authorize, create and login new user. I can:

  1. Integrate WebApi to existing project
  2. Create a new WebApi project and manage the same db

What is best practice?

Thanks

I would suggest moving your shared code (entites, commands and queries etc.) to a different class library and separate MVC from WebAPI. Both of these projects could use the shared code.

The reason for this is that the MVC layer will probably respond with a view containing HTML, CSS and JavaScript while the (Web)API layer will probably return just JSON or XML. I always think of the separation of concerns.

There is no silver bullet; you can do both. You need to decide for yourself which approach is feasible, by comparing the differences and choose the scenario that best fits your requirements.

One thing to keep in mind is that two projects means two applications in IIS, for one because you have two Global.asax that initialize the respective applications. This may or may not be a benefit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM