Search code examples
asp.net-corednx

Enumerating runtime services in an ASP.NET5 Console Application


For my own learning I am experimenting with a DNX console application in Visual Studio 2015 and I am trying to implement the example app shown in this MSDN article by Daniel Roth: https://msdn.microsoft.com/en-us/magazine/dn913182.aspx Under the section: A Cross-Platform .Net Console App

In this example the author prints out a list of the services available from the runtime environment by enumerating the Service property on an IServiceManifest instance which is injected into the Program class via a constructor. In order to give the app access to this interface the author defines an ANI (Assembly Neutral Interface) as the IServiceManifest definition is inside the DNX itself.

This example was written some time ago and:

1) IServiceManifest seems to no longer exist. I did find IRuntimeServices in Microsoft.DNX.Runtime.Abstractions which has the same Services property so I assume it was just renamed.

2) More importantly, Assembly Neutral Interfaces were dropped in a more recent update so I'm not sure how to access the IRuntimeServices interface in order to have it injected into the Program constructor.

I have tried adding a dependency in project.json to Microsoft.DNX.Runtime.Abstractions but the package restore fails. I assume this package is not available on the public nuget feed as it is part of the DNX itself.

Is there a way to create this kind of app now that ANIs have been dropped?

Thanks in advance.


Solution

  • Microsoft.Framework.Runtime.Abstractions has been renamed to Microsoft.Dnx.Runtime.Abstractions in beta7. See this announcement.

    • If you are using DNX beta6 or earlier, add a reference to Microsoft.Framework.Runtime.Abstractions.
    • If you are using DNX beta7, add a reference to Micrsoft.Dnx.Runtime.Abstractions and add the dev feed (https://www.myget.org/F/aspnetvnext/api/v2) to your package sources. Restore should work then.

    Once you have the runtime abstractions package, you'll be able to access IRuntimeEnvironment