Beispiel #1
0
 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);
        }
Beispiel #4
0
 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}");
        }
Beispiel #8
0
    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");
        }
Beispiel #11
0
 public IActionResult Greet()
 {
     ViewBag.Message = _greet.Greet();
     return(View());
 }
Beispiel #12
0
 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);
Beispiel #15
0
 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());
        }
Beispiel #18
0
 public string Get(string name) =>
 _greetingService.Greet(name);
Beispiel #19
0
 public string GetGreeting()
 {
     return(service.Greet());
 }
Beispiel #20
0
 public void OnActionExecuting(ActionExecutingContext context)
 {
     context.ActionArguments["param"] = _greetingService.Greet("Dr. No");
 }
Beispiel #21
0
 public IActionResult Index()
 {
     ViewData["greeting"] = _greetingSvc.Greet();
     return(View());
 }
Beispiel #22
0
        public void DoGreeting()
        {
            string name = _nameProvider.GetName();

            _greetingService.Greet(name);
        }
 public string Index(string id)
 {
     return($"<h1>{_greetingService.Greet(id)}</h1>");
 }