Split encoders into two packages to resolve layering issues

The core package has no external dependencies aside from NetFX-produced packages
This commit is contained in:
Levi B 2015-03-12 11:01:47 -07:00
parent a06d05ffae
commit 8ca2728ef8
25 changed files with 77 additions and 30 deletions

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
VisualStudioVersion = 14.0.22710.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A5A15F1C-885A-452A-A731-B0173DDBD913}"
EndProject
@ -41,6 +41,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.WebEnco
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.WebEncoders.Tests", "test\Microsoft.Framework.WebEncoders.Tests\Microsoft.Framework.WebEncoders.Tests.xproj", "{7AE2731D-43CD-4CF8-850A-4914DE2CE930}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.WebEncoders.Core", "src\Microsoft.Framework.WebEncoders.Core\Microsoft.Framework.WebEncoders.Core.xproj", "{BE9112CB-D87D-4080-9CC3-24492D49CBE6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -229,6 +231,18 @@ Global
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|x86.ActiveCfg = Release|Any CPU
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|x86.Build.0 = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|x86.ActiveCfg = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|x86.Build.0 = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Any CPU.Build.0 = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|x86.ActiveCfg = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -251,5 +265,6 @@ Global
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
{DD2CE416-765E-4000-A03E-C2FF165DA1B6} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
{7AE2731D-43CD-4CF8-850A-4914DE2CE930} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
{BE9112CB-D87D-4080-9CC3-24492D49CBE6} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
EndGlobalSection
EndGlobal

View File

@ -2,49 +2,48 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.DependencyInjection;
namespace Microsoft.Framework.WebEncoders
{
/// <summary>
/// Contains extension methods for fetching encoders from a service provider.
/// Contains extension methods for fetching encoders from an <see cref="IServiceProvider"/>.
/// </summary>
public static class EncoderServiceProviderExtensions
{
/// <summary>
/// Retrieves an IHtmlEncoder from a service provider.
/// Retrieves an <see cref="IHtmlEncoder"/> from an <see cref="IServiceProvider"/>.
/// </summary>
/// <remarks>
/// This method is guaranteed never to return null.
/// It will return a default encoder instance if the service provider does not contain one.
/// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
/// </remarks>
public static IHtmlEncoder GetHtmlEncoder(this IServiceProvider serviceProvider)
{
return serviceProvider?.GetService<IHtmlEncoder>() ?? HtmlEncoder.Default;
return (IHtmlEncoder)serviceProvider?.GetService(typeof(IHtmlEncoder)) ?? HtmlEncoder.Default;
}
/// <summary>
/// Retrieves an IJavaScriptStringEncoder from a service provider.
/// Retrieves an <see cref="IJavaScriptStringEncoder"/> from an <see cref="IServiceProvider"/>.
/// </summary>
/// <remarks>
/// This method is guaranteed never to return null.
/// It will return a default encoder instance if the service provider does not contain one.
/// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
/// </remarks>
public static IJavaScriptStringEncoder GetJavaScriptStringEncoder(this IServiceProvider serviceProvider)
{
return serviceProvider?.GetService<IJavaScriptStringEncoder>() ?? JavaScriptStringEncoder.Default;
return (IJavaScriptStringEncoder)serviceProvider?.GetService(typeof(IJavaScriptStringEncoder)) ?? JavaScriptStringEncoder.Default;
}
/// <summary>
/// Retrieves an IUrlEncoder from a service provider.
/// Retrieves an <see cref="IUrlEncoder"/> from an <see cref="IServiceProvider"/>.
/// </summary>
/// <remarks>
/// This method is guaranteed never to return null.
/// It will return a default encoder instance if the service provider does not contain one.
/// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
/// </remarks>
public static IUrlEncoder GetUrlEncoder(this IServiceProvider serviceProvider)
{
return serviceProvider?.GetService<IUrlEncoder>() ?? UrlEncoder.Default;
return (IUrlEncoder)serviceProvider?.GetService(typeof(IUrlEncoder)) ?? UrlEncoder.Default;
}
}
}

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.WebEncoders
{
@ -50,7 +51,7 @@ namespace Microsoft.Framework.WebEncoders
/// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/>
/// method will be escaped.
/// </summary>
public HtmlEncoder(ICodePointFilter filter)
public HtmlEncoder([NotNull] ICodePointFilter filter)
: this(new HtmlUnicodeEncoder(CodePointFilter.Wrap(filter)))
{
}

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.WebEncoders
{
@ -50,7 +51,7 @@ namespace Microsoft.Framework.WebEncoders
/// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/>
/// method will be escaped.
/// </summary>
public JavaScriptStringEncoder(ICodePointFilter filter)
public JavaScriptStringEncoder([NotNull] ICodePointFilter filter)
: this(new JavaScriptStringUnicodeEncoder(CodePointFilter.Wrap(filter)))
{
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>be9112cb-d87d-4080-9cc3-24492d49cbe6</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.WebEncoders
{
@ -50,7 +51,7 @@ namespace Microsoft.Framework.WebEncoders
/// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/>
/// method will be escaped.
/// </summary>
public UrlEncoder(ICodePointFilter filter)
public UrlEncoder([NotNull] ICodePointFilter filter)
: this(new UrlUnicodeEncoder(CodePointFilter.Wrap(filter)))
{
}

View File

@ -0,0 +1,24 @@
{
"version": "1.0.0-*",
"description": "Contains core encoders for HTML, JavaScript strings, and URLs.",
"compilationOptions": {
"allowUnsafe": true
},
"dependencies": {
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
},
"frameworks": {
"net45": { },
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.ComponentModel": "4.0.0-*",
"System.Diagnostics.Debug": "4.0.10-*",
"System.IO": "4.0.10-*",
"System.Reflection": "4.0.10-*",
"System.Runtime.Extensions": "4.0.10-*",
"System.Threading": "4.0.10-*"
}
}
}
}

View File

@ -1,26 +1,15 @@
{
"version": "1.0.0-*",
"description": "Contains encoders for HTML, JavaScript, and URLs.",
"compilationOptions": {
"allowUnsafe": true
},
"description": "Contains registration and configuration APIs for the core framework encoders.",
"dependencies": {
"Microsoft.Framework.DependencyInjection.Interfaces": "1.0.0-*",
"Microsoft.Framework.OptionsModel": "1.0.0-*",
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" },
"Microsoft.Framework.WebEncoders.Core": "1.0.0-*"
},
"frameworks": {
"net45": { },
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Diagnostics.Debug": "4.0.10-beta-*",
"System.IO": "4.0.10-beta-*",
"System.Reflection": "4.0.10-beta-*",
"System.Runtime": "4.0.20-beta-*",
"System.Runtime.Extensions": "4.0.10-beta-*",
"System.Threading": "4.0.10-beta-*"
}
}
"dnxcore50": { }
}
}