【发布时间】:2017-05-26 08:52:22
【问题描述】:
在浏览 ASP.NET Core 配置的官方文档时,我们可以找到以下示例。这在其他样本中也占主导地位。
public class MyOptions
{
public MyOptions()
{
// Set default value.
Option1 = "value1_from_ctor";
}
public string Option1 { get; set; }
public int Option2 { get; set; } = 5;
}
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration
我正在浏览 ASP.NET Core Caching 存储库,并注意到 Microsoft 团队的操作方式略有不同。
public class MemoryCacheOptions : IOptions<MemoryCacheOptions>
{
// removed stuff
MemoryCacheOptions IOptions<MemoryCacheOptions>.Value
{
get { return this; }
}
}
实施 IOptions 有什么好处?它给了我们什么“魔法”?
【问题讨论】:
标签: asp.net-core