public async Task Invoke( HttpContext context, IGreetingService greetingService) { var message = greetingService.Greet("World (via DI)"); await context.Response.WriteAsync(message); }
public Task Invoke(HttpContext httpContext) { string cacheKey = "GreetingMiddleware-Invoke"; string greeting; // try to get the cached item; null if not found // greeting = _memoryCache.Get(cacheKey) as string; // alternately, TryGet returns true if the cache entry was found if (!_memoryCache.TryGetValue(cacheKey, out greeting)) { // fetch the value from the source greeting = _greetingService.Greet("world"); // store in the cache _memoryCache.Set(cacheKey, greeting, new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromMinutes(1))); _logger.LogInformation($"{cacheKey} updated from source."); } else { _logger.LogInformation($"{cacheKey} retrieved from cache."); } return(httpContext.Response.WriteAsync(greeting)); }
public async Task Invoke(HttpContext context, IGreetingService service) { var message = service.Greet(" user IGreetingService"); await context.Response.WriteAsync(message); await this.next(context); }
public override void Process( TagHelperContext context, TagHelperOutput output) { output.TagName = "p"; output.Content.SetContent(_greetingService.Greet(Name)); }
public string Greet(string userName) { logger.Info($"Attempting to greet user {userName}"); var result = innerService.Greet(userName); logger.Info($"Successfully generated greeting to user {userName}"); return(result); }
public async Task Invoke(HttpContext context, IGreetingService service) { // //var service2 = context.RequestServices.GetService<IGreetingService>(); var message = service.Greet("World (via DI)"); await context.Response.WriteAsync(message); }
public string Index(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } string result = _greetingService.Greet(name); return($"the answer from the service: {result}"); }
public void Configure(IApplicationBuilder app, IGreetingService greetingService) { var routeBuilder = new RouteBuilder(app); routeBuilder.MapGet("{route}", context => { var route = context.GetRouteValue("route").ToString(); return(context.Response.WriteAsync(greetingService.Greet(route))); }); app.UseRouter(routeBuilder.Build()); }
public void OnActionExecuting(ActionExecutingContext context) { object param; if (context.ActionArguments.TryGetValue("param", out param)) { context.ActionArguments["param"] = param.ToString().ToUpper(); } else { context.ActionArguments.Add("param", service.Greet("lilei")); } }
static void Main(string[] args) { IGreetingService service = DoubleCheckedLockingGreetingService.Instance; IGreetingService service_2 = DoubleCheckedLockingGreetingService.Instance; service.Greet("DoubleCheckedLocking"); service_2.Greet("DoubleCheckedLocking"); IGreetingService service_3 = LazyObjectGreetingService.Instance; IGreetingService service_4 = LazyObjectGreetingService.Instance; service_3.Greet("LazyObject"); service_4.Greet("LazyObject"); IGreetingService service_5 = SimpleGreetingService.Instance; IGreetingService service_6 = SimpleGreetingService.Instance; service_5.Greet("Simple"); service_6.Greet("Simple"); }
public IActionResult Greet() { ViewBag.Message = _greet.Greet(); return(View()); }
public string Hello(string name) => _greetingService.Greet(name);
public string Index([FromQuery] string name) { return(_greetingService.Greet(name)); }
public string Hello(string id) => _greetingService.Greet(id);
public string Hello(string name) { return(_greetingService.Greet(name)); }
public string Index(string name) => _greetingService.Greet(name);
public string Index(string name) { string result = _greetingService.Greet(name); return(result.ToUpper()); }
public string Get(string name) => _greetingService.Greet(name);
public string GetGreeting() { return(service.Greet()); }
public void OnActionExecuting(ActionExecutingContext context) { context.ActionArguments["param"] = _greetingService.Greet("Dr. No"); }
public IActionResult Index() { ViewData["greeting"] = _greetingSvc.Greet(); return(View()); }
public void DoGreeting() { string name = _nameProvider.GetName(); _greetingService.Greet(name); }
public string Index(string id) { return($"<h1>{_greetingService.Greet(id)}</h1>"); }