运行时服务不再注入 DNX 控制台应用程序 (RC1)
Runtime services no longer get injected into DNX console app (RC1)
我曾经能够将 IApplicationEnvironment
等运行时服务注入到 DNX 控制台应用程序的 Pogram
class 的构造函数中。但是,使用最新的 CI 版本的 RC1,服务不再被注入:
public Program(IApplicationEnvironment env)
{
if (env == null)
{
// env is null.
throw new ArgumentNullException(nameof(env));
}
}
DNX 平台希望与常规 Program.Main
入口点兼容。因此,他们删除了对 Program
class.
的依赖注入
相反,您可以使用新的 PlatformServices
class,它提供对运行时服务的访问:
public Program()
{
var env = PlatformServices.Default.Application;
}
PlatformServices
class 位于 Microsoft.Extensions.PlatformAbstractions
命名空间中。
ILibraryExporter
和 ICompilerOptionsProvider
等类型现在通过 Microsoft.Extensions.CompilationAbstractions
命名空间中的 CompilationServices
class 公开。
我曾经能够将 IApplicationEnvironment
等运行时服务注入到 DNX 控制台应用程序的 Pogram
class 的构造函数中。但是,使用最新的 CI 版本的 RC1,服务不再被注入:
public Program(IApplicationEnvironment env)
{
if (env == null)
{
// env is null.
throw new ArgumentNullException(nameof(env));
}
}
DNX 平台希望与常规 Program.Main
入口点兼容。因此,他们删除了对 Program
class.
相反,您可以使用新的 PlatformServices
class,它提供对运行时服务的访问:
public Program()
{
var env = PlatformServices.Default.Application;
}
PlatformServices
class 位于 Microsoft.Extensions.PlatformAbstractions
命名空间中。
ILibraryExporter
和 ICompilerOptionsProvider
等类型现在通过 Microsoft.Extensions.CompilationAbstractions
命名空间中的 CompilationServices
class 公开。