Real World Asp.Net WebApi Applications

7,038 views
6,673 views

Published on

Best practices and insights for building great Asp.Net WebApi applications

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,038
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
15
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Real World Asp.Net WebApi Applications

  1. 1. How to build real world single pageapplications
  2. 2.  Git AppHarbor PaaS MongoDB integration IoC/Dependency Injection Tests with nUnit & Moq CI + CD Repository Pattern Exception Management Authentication & Authorization
  3. 3.  Bootstrap.MVC for responsive design Backbone.js client MVC lib Client Side session management Client side authentication
  4. 4.  Build and deploy an App in the Cloud
  5. 5.  WebApi is Self Hosted and more flexible WebApi Has Content Negotiation Separation of concerns • Allows detaching the website from the Api
  6. 6. User Question Vote• Name • QuestionText • UserId• Password • IsOpenToVotes • Answer• PassSalt • List<Vote>• AccessToken
  7. 7. The Api…
  8. 8.  User Model: public class User : Entity public string Name { get; set; } public string Password { get; set; } public string PasswordSalt { get; set; } public string AccessToken { get; set; }
  9. 9.  User Api Model: public class User public string Id { get; set; } public string Name { get; set; } public string AccessToken { get; set; }
  10. 10.  Use AttributeRouting nuGet Packagepublic class SampleController : ApiController{ [GET("Sample")] public List<Tweet> Index() { /* ... */ } [POST("Sample")] public void Create() { /* ... */ } [PUT("Sample/{id}")] public void Update(int id) { /* ... */ } [Route("Sample/Any-Method-Will-Do")] public string Wildman() { /* ... */ }}
  11. 11. Main
  12. 12. DependencyMain Injector
  13. 13.  Pros • Decoupling • Easy Testing, Isolating and Mocking Cons • Complicates the code • New set of bugs
  14. 14.  Add StructureMap.MVC4 nuGet Package to the website Build classes with IoC in mind Add Repository Registry Add Registry to Ioc.cs in Depedency Resolution folder
  15. 15.  Not a part of Asp.Net. It’s just a best practice Allows: • Code reuse • Decoupling • IoC/Dependency Injection Current Standard – Low learning curve for developers
  16. 16.  void Add(IEnumerable<T> entities) IQueryable<T> All(Expression<Func<T, bool>> criteria) void Delete(Expression<Func<T, bool>> criteria) void Update(IEnumerable<T> entities) ...
  17. 17. The Client…
  18. 18.  Backbone.js Knockout.js Javascript.MVC Ember.js Angular.js Batman.js Sammy.js YUI
  19. 19.  Twitter Bootstrap Foundation 3 by Zurb HTML5 Boilerplate LessFramework…
  20. 20.  Attribute Routing Twitter Bootstrap Twitter Bootstrap Starter Layout Page Great Backbone.js Book
  21. 21.  Chrome Extensions • Dev Http Client • Edit this Cookie • Clear Cache • JSON View Responsinator
  22. 22.  effie.arditi@gmail.com @fe_rdt Github: EffieArditi

×