📜  选项模式如何使用 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:52.335000             🧑  作者: Mango

代码示例1
// AppSettingsController.cs
[Route("appsettings")]
public class AppSettingsController : Controller
{
    ...
    protected readonly IOptions _roundTheCodeSyncOptions;
 
    public AppSettingsController(..., IOptions roundTheCodeSyncOptions)
    {
        ...
        _roundTheCodeSyncOptions = roundTheCodeSyncOptions;
    }
 
    ...
 
    [Route("second-way")]
    public IActionResult SecondWay()
    {
        return Content(_roundTheCodeSyncOptions.Value.Title, "text/plain");
    }
}