如何使用MVC& WebApi作为单一解决方案中的不同项目 [英] How to use MVC & WebApi as a different project in single solution

查看:52
本文介绍了如何使用MVC& WebApi作为单一解决方案中的不同项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WebApi,一个用于业务逻辑的控制台应用程序,一个Mvc在一个解决方案中都是不同的项目。如何将这3个组合到我的应用程序中。这类逻辑工作背后的逻辑是什么?请任何人帮助我,谢谢你的回复

I have one WebApi, one console application for business logic and one Mvc all are different project in a single solution. How can i combine these 3 into my application. What is the logic behind for these type of logical work. Please anybody help me and thank you for your response

推荐答案

解决方案只是一个项目集合,它唯一的特殊能力是添加一个项目引用...所以如果一个项目需要另一个项目的dll,则添加项目引用,客户端项目始终使用解决方案中其他项目生成的dll。这意味着所有项目总是会看到它引用的所有项目的最新代码。



在您的情况下,您的任何项目都不太可能引用彼此的dlls因为MVC和WebApi项目是通过http访问的。



因此,如果您的MVC项目是独立的,您可以通过(例如)http:/访问它/本地主机:1234 /首页/索引。如果WebApi是独立的,您可以通过http:// localhost:5678 / Product / Get / 1234引用它。如果两个项目和控制台应用程序都在同一个解决方案中没有任何变化。如果您的控制台应用程序想要调用MVC,则调用http:// localhost:1234 / Home / Index。如果您的Index方法想要调用WebApi,则调用http:// localhost:5678 / Product / Get / 1234。将它们全部集中在一个解决方案中并没有改变任何东西。



当然,唯一需要注意的是,在部署代码时,不会硬编码代码中的URL他们的位置会有所不同。
A solution is just a collection of projects, its only special ability is to add a project reference...so if one project needs the dll of another you add a project reference and the client project always uses the dll generated by the other project that is in the solution. This means all projects always see the up-to-date code from all projects it references.

In your case it is unlikely any of your projects are referencing each others dlls as the MVC and WebApi projects are accessed via http instead.

So if your MVC project was stand-alone you'd access it via (for example) http://localhost:1234/Home/Index. If the WebApi was stand-alone you'd reference it via http://localhost:5678/Product/Get/1234. If both projects, and the console app, are all in the same solution nothing changes. If your console app wants to call MVC it calls http://localhost:1234/Home/Index. If your Index method wants to call WebApi it calls http://localhost:5678/Product/Get/1234. Having them all in one solution doesn't change anything.

The only caveat being, of course, don't hard-code urls in your code, when you deploy them their locations will be different.


这篇关于如何使用MVC& WebApi作为单一解决方案中的不同项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆