PlatformAbstraction类在现在的asp.net core中已经废弃了,但是此类的设计还是不错的,可以借鉴,源码如下:
namespace Microsoft.Extensions.PlatformAbstractions
{
public class PlatformServices
{
private PlatformServices()
{
Application = new ApplicationEnvironment();
} public static PlatformServices Default { get; } = new PlatformServices(); public ApplicationEnvironment Application { get; }
}
}
利用static以及private关键字的访问域来实例化另一个类ApplicationEnvironment,这种实现还是挺巧的。