Goodbye Platform Abstractions!!

Goodbye Platform Abstractions!!

Apr 26, 2017     Viewed 4843 times 1 Comments
Posted in #Platform Abstractions 

The Platform Abstraction was good piece of technology in ASP.NET Core 1, this component was contain a bunch of the APIs related to the application environment.

But after a long discussion here to remove this component completely from ASP.NET Core, today I would like to say goodbye Platform Abstractions!! because this component will no longer available in ASP.NET Core 2.0.

Equivalent APIs

The first question may asked after reading the blog post title is: what is the equavalent APIs for Platform Abstractions? let me show you the replacing APIs usage below:

PlatformServices.Default.Application.ApplicationBasePath

AppContext.BaseDirectory

AppDomain.CurrentDomain.BaseDirectory

PlatformServices.Default.Application.ApplicationName

Assembly.GetEntryAssembly().GetName().Name

AppDomain.CurrentDomain.SetupInformation.ApplicationName

PlatformServices.Default.Application.ApplicationVersion

Assembly.GetEntryAssembly().GetName().Version

PlatformServices.Default.Application.RuntimeFramework

Assembly.GetEntryAssembly().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName

AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName

IMHO this is the right choice in the right time to remove this component, because Reflection APIs nowadays is rich enough in .NET Core to accomplish the same goal.


1 Comment

quetzalcoatl (1/2/2018 12:36:38 PM)

Regarding "Assembly.GetEntryAssembly()"

You have to be extra careful, because sometimes GetEntryAssembly returns NULL or not the assembly you would expect - for example in Test Runners.

Regarding "PlatformServices.Default.Application.ApplicationName"

Actually, in ASP CORE 2.0 there is no "SetupInformation" in "AppDomain.CurrentDomain". The correct way to get the ApplicationName is to use IHostingEnvironment service from DI. For example:

public class Startup
{
public Startup(IHostingEnvironment env)
{
var foo = env.ApplicationName;


Leave a Comment