ho provato anche così:
e poi:codice:{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*", "MySettings": { "DbConnection": "abc", "Email": "abc@domain.com", "SMTPPort": "5605" } }
ma mi va in errore:codice:namespace CSharpNetCoreWeb.Controllers { public class HomeController : Controller { private readonly ILogger<HomeController> _logger; private IConfiguration configuration { get; } public HomeController(ILogger<HomeController> logger) { _logger = logger; string dbConn = configuration.GetSection("MySettings").GetSection("DbConnection").Value; Debug.WriteLine("STRINGA: " + dbConn); } ......................... } }
sinceramente non capisco, ho letto tonnellate di esempi in giro, e anche la documentazione!codice:System.NullReferenceException: 'Object reference not set to an instance of an object.' CSharpNetCoreWeb.Controllers.HomeController.configuration.get ha restituito null.

Rispondi quotando