This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| var innerI, | |
| i = 0, | |
| urls = [ 'http://www.google.com', 'http://www.yahoo.com' ], | |
| urlLength = urls.length; | |
| for (; i < urlLength; i++) { | |
| innerI = i; | |
| http.get(urls[i], function() { console.log('i:' + innerI); }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http'); | |
| function makeResponseHandler(i) { | |
| return function(response) { | |
| console.log('i: ' + i); | |
| }; | |
| } | |
| var i = 0, | |
| urls = [ 'http://www.google.com', 'http://www.yahoo.com' ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| var urls = [ 'http://www.google.com', 'http://www.yahoo.com' ], | |
| urlLength = urls.length; | |
| for (let i = 0; i < urlLength; i++) { | |
| http.get(urls[i], function() { console.log('i: ' + i); }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'), | |
| urls = [ 'http://www.google.com', 'http://www.yahoo.com' ]; | |
| urls.forEach((e, i) => http.get(e, _ => console.log('i: ' + i))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class BaseController : Controller | |
| { | |
| protected BaseController(UserProfile userProfile) | |
| { | |
| UserProfile = userProfile; | |
| } | |
| protected UserProfile UserProfile { get; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AppNinjectModule : NinjectModule | |
| { | |
| public override void Load() | |
| { | |
| // UserProfileManager is just a factory that manages the life cycle | |
| // of UserProfile, because it has dependencies of its own (e.g. WCF | |
| // service client) | |
| Bind<UserProfile>() | |
| .ToMethod(ctx => ctx.Get<UserProfileManager>().GetUserProfile()) | |
| .InRequestScope(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class HomeController : Controller | |
| { | |
| public ActionResult Index() | |
| { | |
| return View(); | |
| } | |
| } | |
| public class HomeControllerTests | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class HomeController : BaseController | |
| { | |
| public HomeController(UserProfile userProfile) : base(userProfile) | |
| { | |
| } | |
| public ActionResult Index() | |
| { | |
| return View(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UserProfileActionFilterAttribute : ActionFilterAttribute | |
| { | |
| private readonly UserProfile _userProfile; | |
| public UserProfileActionFilterAttribute(UserProfile userProfile) | |
| { | |
| _userProfile = userProfile; | |
| } | |
| public override void OnActionExecuting(ActionExecutingContext filterContext) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AdminController : Controller | |
| { | |
| public ActionResult Index() | |
| { | |
| // In real production code you should probably use the AuthorizeAttribute | |
| // instead of authorizing/forbidding the user inside an action method | |
| var user = (UserProfile)ViewBag.User; | |
| if (!user.IsAdmin) | |
| { | |
| return new HttpStatusCodeResult(HttpStatusCode.Forbidden); |