Rename Load() to Instance for DependencyContext

This commit is contained in:
Pavel Krymets 2016-01-05 15:35:32 -08:00
parent e39d30ba9c
commit 10ecaeba65

View file

@ -12,6 +12,8 @@ namespace Microsoft.Extensions.DependencyModel
{ {
private const string DepsResourceSufix = ".deps.json"; private const string DepsResourceSufix = ".deps.json";
private static Lazy<DependencyContext> _defaultContext = new Lazy<DependencyContext>(LoadDefault);
public DependencyContext(string target, string runtime, CompilationOptions compilationOptions, Library[] compileLibraries, Library[] runtimeLibraries) public DependencyContext(string target, string runtime, CompilationOptions compilationOptions, Library[] compileLibraries, Library[] runtimeLibraries)
{ {
Target = target; Target = target;
@ -21,6 +23,8 @@ namespace Microsoft.Extensions.DependencyModel
RuntimeLibraries = runtimeLibraries; RuntimeLibraries = runtimeLibraries;
} }
public static DependencyContext Default => _defaultContext.Value;
public string Target { get; } public string Target { get; }
public string Runtime { get; } public string Runtime { get; }
@ -31,7 +35,7 @@ namespace Microsoft.Extensions.DependencyModel
public IReadOnlyList<Library> RuntimeLibraries { get; } public IReadOnlyList<Library> RuntimeLibraries { get; }
public static DependencyContext Load() private static DependencyContext LoadDefault()
{ {
var entryAssembly = (Assembly)typeof(Assembly).GetTypeInfo().GetDeclaredMethod("GetEntryAssembly").Invoke(null, null); var entryAssembly = (Assembly)typeof(Assembly).GetTypeInfo().GetDeclaredMethod("GetEntryAssembly").Invoke(null, null);
var stream = entryAssembly.GetManifestResourceStream(entryAssembly.GetName().Name + DepsResourceSufix); var stream = entryAssembly.GetManifestResourceStream(entryAssembly.GetName().Name + DepsResourceSufix);