Created
April 20, 2021 20:17
-
-
Save manoj-choudhari-git/7b77cb7c11572dc070641b0c06cb8301 to your computer and use it in GitHub Desktop.
Using Configure method to register the options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Startup.cs | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Some code... | |
services.Configure<MailFeature>(Configuration.GetSection(nameof(MailFeature))); | |
// Some other code.... | |
} | |
} | |
// Inject dependency in controller. | |
// using Microsoft.Extensions.Options; | |
public class HomeController : Controller | |
{ | |
private readonly ILogger<HomeController> _logger; | |
private readonly IOptions<MailFeature> mailFeatureOptions; | |
// the Options class is directly injected | |
public HomeController(ILogger<HomeController> logger, IOptions<MailFeature> mailFeatureOptions) | |
{ | |
_logger = logger; | |
this.mailFeatureOptions = mailFeatureOptions; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment