better example

alphons <alphons@heijden.com> 20 Jan 2025, 22:32
2f9e402843b51c6f35f3963a08179ccb3b092dec
1 files changed
  • SessionScopedTest/Controllers/ExampleController.cs
diff --git a/SessionScopedTest/Controllers/ExampleController.cs b/SessionScopedTest/Controllers/ExampleController.cs
index ad50c31..9c960f1 100644
--- a/SessionScopedTest/Controllers/ExampleController.cs
+++ b/SessionScopedTest/Controllers/ExampleController.cs
@@ -5,17 +5,18 @@ namespace SessionScopedTest.Controllers;
public class ExampleController(SessionScopedFactory<ExampleService> factory) : ControllerBase
{
+ private readonly ExampleService exampleService = factory.Instance;
public async Task<IActionResult> Index()
{
HttpContext.Session.SetString("Started", DateTime.Now.ToString());
- var result = await factory.Instance.SetNameAsync($"alphons {Guid.NewGuid()}");
+ var result = await exampleService.SetNameAsync($"alphons {Guid.NewGuid()}");
return Ok("name is set, check url /Example/WhatsYourName");
}
public async Task<IActionResult> WhatsYourName()
{
- var name = await factory.Instance.GetNameAsync();
+ var name = await exampleService.GetNameAsync();
return Ok(name);
}