1- using System . Diagnostics ;
1+ using System . Diagnostics ;
22using System . Runtime . CompilerServices ;
33using System . Text . Json ;
44using Microsoft . AspNetCore . Mvc ;
1111
1212namespace Steeltoe . Samples . CosmosDb . Controllers ;
1313
14- public class HomeController : Controller
14+ public sealed class HomeController ( ConnectorFactory < CosmosDbOptions , CosmosClient > connectorFactory ) : Controller
1515{
16- private readonly ILogger < HomeController > _logger ;
17- private readonly Connector < CosmosDbOptions , CosmosClient > _connector ;
18-
19- public HomeController ( ILogger < HomeController > logger , ConnectorFactory < CosmosDbOptions , CosmosClient > connectorFactory )
16+ private static readonly JsonSerializerOptions SerializerOptions = new ( )
2017 {
21- _logger = logger ;
22- _connector = connectorFactory . Get ( ) ;
23- }
18+ WriteIndented = true
19+ } ;
20+
21+ private readonly Connector < CosmosDbOptions , CosmosClient > _connector = connectorFactory . Get ( ) ;
2422
2523 public async Task < IActionResult > Index ( CancellationToken cancellationToken )
2624 {
@@ -31,10 +29,7 @@ public async Task<IActionResult> Index(CancellationToken cancellationToken)
3129 var model = new CosmosDbViewModel
3230 {
3331 ConnectionString = _connector . Options . ConnectionString ,
34- OptionsJson = JsonSerializer . Serialize ( client . ClientOptions , new JsonSerializerOptions
35- {
36- WriteIndented = true
37- } ) ,
32+ OptionsJson = JsonSerializer . Serialize ( client . ClientOptions , SerializerOptions ) ,
3833 Database = _connector . Options . Database
3934 } ;
4035
@@ -46,7 +41,7 @@ public async Task<IActionResult> Index(CancellationToken cancellationToken)
4641 return View ( model ) ;
4742 }
4843
49- private async IAsyncEnumerable < SampleObject > GetAllAsync ( Container container , [ EnumeratorCancellation ] CancellationToken cancellationToken )
44+ private static async IAsyncEnumerable < SampleObject > GetAllAsync ( Container container , [ EnumeratorCancellation ] CancellationToken cancellationToken )
5045 {
5146 using FeedIterator < SampleObject > iterator = container . GetItemLinqQueryable < SampleObject > ( ) . ToFeedIterator ( ) ;
5247
0 commit comments