运行时服务不再注入DNX控制台应用程序(RC1) [英] Runtime services no longer get injected into DNX console app (RC1)

查看:107
本文介绍了运行时服务不再注入DNX控制台应用程序(RC1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经能够将诸如 IApplicationEnvironment 之类的运行时服务注入DNX的 Pogram 类的构造函数中控制台应用程序。但是,使用RC1的最新CI版本,将不再注入服务:

I used to be able to inject runtime services like IApplicationEnvironment into the constructor of the Pogram class of a DNX console application. However, using the latest CI build of RC1, the services no longer get injected:

public Program(IApplicationEnvironment env)
{
    if (env == null)
    {
        // env is null.
        throw new ArgumentNullException(nameof(env));
    }
}


推荐答案

DNX平台希望与常规 Program.Main 入口点兼容。因此,他们将依赖项注入删除到 Program 类中。

The DNX platform wants to be compatible with regular Program.Main entry points. Therefore they removed dependency injection into the Program class.

相反,您可以使用新的 PlatformServices 类,用于访问运行时服务:

In stead, you can use the new PlatformServices class which provides access to runtime services:

public Program()
{
    var env = PlatformServices.Default.Application;
}

PlatformServices 类位于 Microsoft.Extensions.PlatformAbstractions 命名空间。

诸如 ILibraryExporter ICompilerOptionsProvider 现在通过

Types like ILibraryExporter and ICompilerOptionsProvider are now exposed through the CompilationServices class in the Microsoft.Extensions.CompilationAbstractions namespace.

>参考

这篇关于运行时服务不再注入DNX控制台应用程序(RC1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆