Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Last active April 20, 2021 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/56e81cbda6bde90ff7633cf7d424ea4d to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/56e81cbda6bde90ff7633cf7d424ea4d to your computer and use it in GitHub Desktop.
ConfigurationBinder.Get <T> usage example
// 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