Last active
April 20, 2021 20:27
-
-
Save manoj-choudhari-git/56e81cbda6bde90ff7633cf7d424ea4d to your computer and use it in GitHub Desktop.
ConfigurationBinder.Get <T> usage example
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... | |
MailFeature mailFeature = Configuration.GetSection("MailFeature").Get<MailFeature>(); | |
services.AddSingleton(mailFeature); | |
// Some other code.... | |
} | |
} | |
// Inject dependency in controller. | |
public class HomeController : Controller | |
{ | |
private readonly ILogger<HomeController> _logger; | |
private readonly MailFeature mailFeature; | |
// the Options class is directly injected | |
public HomeController(ILogger<HomeController> logger, MailFeature mailFeature) | |
{ | |
_logger = logger; | |
this.mailFeature = mailFeature; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment