且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC和Angularjs一起+的ASP.NET Web API

更新时间:2022-11-23 12:53:12

是的,明智的做法是把两者结合起来。显然,取决于具体的项目,你需要调整一些变量的最终解决方案。

什么你的建议实际上是我们在过去的2个或3个项目堆栈,这里的几个变种,并有根据具体的要求。我们使用的WebAPI + DurandalJS,+的WebAPI淘汰赛......所有的工作真的很好:) AngularJS似乎已经卡住的历史最久,国内逐渐流行到我们公司,以及在社会上的其余部分(这是一个决定对我来说因子)

当前技术堆栈。

  + ------------------------------------ +
                            |用法|
  + ------------------------- + ----------------------- ------------- +
  | AngularJS |该客户端应用程序的Web或移动|
  + ------------------------- + ----------------------- ------------- +
  |的WebAPI |为了您所有的数据访问需求|
  + ------------------------- + ----------------------- ------------- +
  | OAuth的&安培;承载令牌|对于认证和放大器;授权|
  + ------------------------- + ----------------------- ------------- +
  | SQL服务器和放大器; EF /任何|持久性|
  |任何其他NOSQL变种| &安培;存储|
  + ------------------------- + ----------------------- ------------- +
  |角UI / | |
  |角料|基本UI组件|
  + ------------------------- + ----------------------- ------------- +
  |武士刀|项目为收藏|
  | |在MS-Stack的支持OWIN |
  + ------------------------- + ----------------------- ------------- +
  | CORS |标准实施|
  | |跨域请求|
  + ------------------------- + ----------------------- ------------- +

好处:


  • Web应用程序可以移植到移动很容易(如果写在你意识到你可能会去移动这样的方式)


  • 您可以使用其他的服务很容易地访问API /应用程序,你应该选择...加上API的凉爽(相对于传统的访问机制)


  • AngularJS允许强大而结构化的客户端code(不,你不能做没有角,但在我的经验框架实施更好的做法,您应该坚持他们正确地)


  • 开始听起来像一个破纪录,但我们都知道,AngularJS是超级测试的


  • 您可以使用的。净捆绑如果你害怕的的NodeJS之类咕噜/一饮而尽


    • 这并不是说你必须要害怕它(但熟悉>陌生)

    • 只要确保在客户端code被写在一个Minsafe方式


  • Visual Studio是实际上是相当冷静地发展,特别是与他们的新的重点放在开源的支持已晚。集成点阄 AngularJS ,节点一>(你可能会在某个时候使用),显然ASP.Net MVC


缺点:


  • 如果您不熟悉角有一个很好的醇'的学习曲线


  • 的验证可能重复


    • 在为了减少往返/回调,这显然preferable通过正确的数据发送第一个去。因此,在几个(或大多数)的情况下,我们需要重复一些数据级验证的JavaScript中


  • 虽然它可能不适用,而且是一个有点长镜头......我一直在客户那里他们严格想用一切MS,因为开源是不太安全,因为人有访问框架code ...进入数字。因此,请确保他们是开放的使用SPA框架是开源的(这可以适用于任何其他的框架或工具)(和所有与它去)


  • 复制安全。你需要确保以确保API和放大器;应用程序。 (由于在这两个层之间的断开连接)


  • 您就需要学习CORS是如何工作的,以及如何正确impliment它作为可能是你的API和Web应用程序将无法在同一个域/产地


也。值得一读:


  1. Pros和缺点RESTful架构


  2. 宁静的WebAPI VS常规控制器(A previous问题,我问,当它来设计/理解的WebAPI和放大器; REST设计)


I would like to know the advantages and disadvantages of using these 2 worlds:

  • ASP.NET MVC and Angularjs together(without razor, Angularjs will do the job).
  • AngularJS(front end) + ASP.NET Web API(back end).

We are focusing on SPA/Mini-SPA for a medium/large Enterprise project with a lot of server side business rules and calculations. Im focusing on security too.

The advantages and disadvantages opinions would help me to find the aswere for this question inside my head:

Would it be a wise decision to use ASP.NET Web API(backend), ASP.NET MVC and Angularjs together?

Yes, it would be wise to combine the two. Obviously depending on the exact project, you need to tweak some of the variables in the final solution.

What you are suggesting has actually been our stack for the last 2 or 3 projects, with a few variants here and there based on specific requirements. We've used WebAPI + DurandalJS, WebAPI + Knockout... All work really well :) AngularJS seems to have stuck around the longest, gaining popularity internally to our company, as well as in the rest of the community (which is a deciding factor for me)

Current Tech Stack.

                            +------------------------------------+
                            |               Usage                |
  +-------------------------+------------------------------------+
  | AngularJS               | The client app web, or mobile      |
  +-------------------------+------------------------------------+    
  | WebAPI                  | For all your data access needs     |
  +-------------------------+------------------------------------+
  | OAuth & Bearer Tokens   | For Authentication & Authorization |
  +-------------------------+------------------------------------+
  | SQL Server & EF / any   |  Persistence                       |
  | any other noSQL variant |  & Storage                         |
  +-------------------------+------------------------------------+
  | Angular-UI /            |                                    |
  | Angular-Material        | Base UI components                 |
  +-------------------------+------------------------------------+
  | Katana                  | Collection of projects for         |
  |                         | supporting OWIN on MS-Stack        |
  +-------------------------+------------------------------------+
  | CORS                    | Standard for implementing          |
  |                         | cross domain requests              |
  +-------------------------+------------------------------------+

Benefits:

  • Web App can be ported to mobile quite easily (if written in such a way that you're aware that you might be going mobile)

  • You have an API that you can easily access using other services / apps should you choose to... plus API's are cool (compared to legacy access mechanisms)

  • AngularJS allows for powerful yet structured client side code (not that you cant do it without Angular, but in my experience the framework enforces better practices, should you adhere to them correctly)

  • Starting to sound like a broken record, but as we all know, AngularJS is super testable

  • You can make use of the .Net bundling if you're scared of NodeJS and things like grunt/gulp

    • Not that you have to be scared of it (but familiarity > unfamiliarity)
    • Just make sure the client side code gets written in a Minsafe way
  • Visual Studio is actually quite cool to develop in, specifically with their new focus on open source support of late. Lots of integration points for AngularJS, Node (which you'll probably use at some point), and obviously ASP.Net MVC

Cons:

  • If your not familiar with Angular there's a nice ol' learning curve

  • Possible duplication of validation

    • In order to reduce round trips/callbacks, it's obviously preferable to send through correct data on the first go. So in a few (or most) instances, we needed to duplicate some of the data level validations in JavaScript
  • Although it might not be applicable, and is a bit of a long shot... I've been at a client where they strictly want to use everything MS because opensource is "less secure", because people have access to the framework code... go figure. So make sure that they're open to using a SPA framework that's open source (this could apply to any other framework or tool) (and all that goes with it)

  • Duplication in security. You'll need to make sure to secure the API & the application. (As there is a disconnect between the two layers)

  • You'll need to learn how CORS works, and how to impliment it correctly as its likely that your API and web app will not be on the same domain/origin

Also. Worth taking a read:

  1. Pros And Cons Of Restful Architecture

  2. Restful WebAPI vs Regular Controllers (A previous question I asked when it came to designing / understanding WebAPI & REST designs)