A using declaration disposes a compatible resource automatically when execution reaches the end of its enclosing scope. For a method, that scope ends when the method returns. section 5.3.5
Managing CSV import resources
A board-game seed operation declares StreamReader and CsvReader with using. The importer reads records, creates entities, and saves them; both disposable objects are released when the method ends. section 5.3.5
var config = new CsvConfiguration(CultureInfo.GetCultureInfo("pt-BR"))
{
HasHeaderRecord = true,
Delimiter = ";",
};
using var reader = new StreamReader(
System.IO.Path.Combine(_env.ContentRootPath, "Data/bgg_dataset.csv"));
using var csv = new CsvReader(reader, config);
var existingBoardGames = await _context.BoardGames
.ToDictionaryAsync(bg => bg.Id);
var existingDomains = await _context.Domains
.ToDictionaryAsync(d => d.Name);
var existingMechanics = await _context.Mechanics
.ToDictionaryAsync(m => m.Name);
var now = DateTime.Now;
This implementation shows using declarations alongside CSV configuration, file-path construction, database lookups, and import initialization. section 5.3.5
