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