Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Added IWebHostEnvironment polyfill
Browse files Browse the repository at this point in the history
Minimal implementation for `MapPathWebRoot` method.
  • Loading branch information
leekelleher committed May 5, 2022
1 parent f354c9f commit bc8e6a9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Core/Hosting/AspNetFxWebHostEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if NET472
using Microsoft.AspNetCore.Hosting;
using Umbraco.Core.IO;

namespace Umbraco.Core.Hosting
{
internal sealed class AspNetFxWebHostEnvironment : IWebHostEnvironment
{
public string MapPathWebRoot(string path)
{
return IOHelper.MapPath(path);
}
}
}
#endif
10 changes: 10 additions & 0 deletions src/Core/Hosting/IWebHostEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#if NET472
namespace Microsoft.AspNetCore.Hosting
{
// https://github.com/dotnet/aspnetcore/blob/v6.0.0/src/Hosting/Abstractions/src/IWebHostEnvironment.cs
public interface IWebHostEnvironment
{
string MapPathWebRoot(string path);
}
}
#endif
19 changes: 19 additions & 0 deletions src/Core/Hosting/WebHostEnvironmentExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if NET5_0
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Web.Common.DependencyInjection;

namespace Microsoft.AspNetCore.Hosting
{
// https://github.com/umbraco/Umbraco-CMS/blob/v10/contrib/src/Umbraco.Web.Common/Extensions/WebHostEnvironmentExtensions.cs
internal static class WebHostEnvironmentExtensions
{
public static string MapPathWebRoot(this IWebHostEnvironment webHostEnvironment, string path)
{
var hostingEnvironment = StaticServiceProvider.Instance
.GetRequiredService<Umbraco.Cms.Core.Hosting.IHostingEnvironment>();

return hostingEnvironment.MapPathWebRoot(path);
}
}
}
#endif
3 changes: 3 additions & 0 deletions src/Core/Runtime/UmbracoPolyfillComposer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if NET472
using Microsoft.AspNetCore.Hosting;
using Umbraco.Core.Composing;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
Expand All @@ -17,6 +18,8 @@ public void Compose(Composition composition)

composition.RegisterUnique<IHostingEnvironment, AspNetFxHostingEnvironment>();

composition.RegisterUnique<IWebHostEnvironment, AspNetFxWebHostEnvironment>();

composition.RegisterUnique<IIOHelper, IOHelperPolyfill>();

composition.RegisterUnique<IJsonSerializer, UmbracoPolyfillJsonSerializer>();
Expand Down

0 comments on commit bc8e6a9

Please sign in to comment.