简体   繁体   English

Web Api和web ui在同一个应用程序/服务中

[英]Web Api and web ui in same application/service

For my AngularJS web application I use Azure Service Fabric as my backend. 对于我的AngularJS Web应用程序,我使用Azure Service Fabric作为我的后端。 For that I created a stateless web api service. 为此我创建了一个无状态的web api服务。

Do I have to put the frontend /client-side AngularJS code in the same application type or the same stateless service? 我是否必须将前端/客户端AngularJS代码放在相同的应用程序类型或相同的无状态服务中? Is it useful to create another stateless service for the web ui? 为web ui创建另一个无状态服务是否有用?

As others have mentioned, you can host your Angular web app anywhere you like; 正如其他人所提到的,您可以随心所欲地托管您的Angular Web应用程序; there are no restrictions imposed by Service Fabric in this regard. 在这方面,Service Fabric没有施加任何限制。

That said, in your case a simple solution is to have your front-end web app and your web api in the same stateless service. 也就是说,在您的情况下,一个简单的解决方案是让您的前端Web应用程序和您的web api处于相同的无状态服务中。 Basically you treat this as a regular old ASP.NET MVC application, and ASP.NET MVC makes it fairly easy to have an API and web UI in the same MVC project. 基本上,您将此视为常规的旧ASP.NET MVC应用程序,而ASP.NET MVC使得在同一MVC项目中拥有API和Web UI变得相当容易。 Here are a couple examples of this: 以下是一些例子:

ASP.NET 5 MVC application with an API and a UI: https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/Chatter 带有API和UI的ASP.NET 5 MVC应用程序: https//github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/Chatter

Single-page jQuery app with an API self-hosted with Katana: https://github.com/Azure-Samples/service-fabric-dotnet-management-party-cluster/tree/master/PartyCluster 单页jQuery应用程序,其中包含一个由Katana自托管的API: https//github.com/Azure-Samples/service-fabric-dotnet-management-party-cluster/tree/master/PartyCluster

As to the question of why do you need Service Fabric to host a front-end file. 至于为什么需要Service Fabric来托管前端文件的问题。 There are trade-offs here. 这里有权衡取舍。 Assuming the front-end is a web application that's meant to be part of a larger Service Fabric application - as it is in your case - it's nice to have everything in one place using one set of tools on the same SDK with the same deployment process hosted on the same cluster, rather than having a completely separate process, tools, SDK, and hosting environment for one part of your application. 假设前端是一个Web应用程序,它应该是一个更大的Service Fabric应用程序的一部分 - 就像你的情况一样 - 很高兴在一个地方使用一组工具在同一个SDK上使用相同的部署过程托管在同一个集群上,而不是为应用程序的一部分提供完全独立的流程,工具,SDK和托管环境。 You also get all the Service Fabric goodness like rolling upgrades, health monitoring, high availability and auto failover, etc. The downside is that you don't get the super easy-to-use tools for web applications that come with, say, Azure App Service. 您还可以获得所有Service Fabric的优点,如滚动升级,运行状况监控,高可用性和自动故障转移等。缺点是您没有获得Azure附带的Web应用程序的超级易用工具。应用服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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