Permalink
Browse files

Remove System.Web reference from SignalR.Server

- Created new SignalR.AspNet assembly.
- Registered ASP.NET specific abstractions in a PreApplicationStart method.
- Created package for SignalR.AspNet
- Moved routing to SignalR.AspNet.
- Removed RequestContext from PersistentConnectionFactory.
  • Loading branch information...
1 parent 31bf653 commit bb2170629cbe5a12c735160d632710fd4464c3e3 @davidfowl davidfowl committed Dec 29, 2011
Showing with 230 additions and 58 deletions.
  1. +2 −2 SignalR/AspNet/PersistentConnectionHandler.cs → SignalR.AspNet/AspNetHost.cs
  2. +1 −1 {SignalR/AspNet → SignalR.AspNet}/AspNetRequest.cs
  3. 0 {SignalR/AspNet → SignalR.AspNet}/AspNetResponse.cs
  4. +29 −0 SignalR.AspNet/Bootstrapper.cs
  5. +40 −0 SignalR.AspNet/BuildManagerTypeLocator.cs
  6. +14 −0 SignalR.AspNet/BuildManagerTypeResolver.cs
  7. 0 {SignalR/Web → SignalR.AspNet}/HttpTaskAsyncHandler.cs
  8. +3 −3 {SignalR/AspNet → SignalR.AspNet}/HubModule.cs
  9. 0 {SignalR → SignalR.AspNet/Infrastructure}/TaskWrapperAsyncResult.cs
  10. +6 −0 SignalR.AspNet/Properties/AssemblyInfo.cs
  11. +15 −0 SignalR.AspNet/Properties/SignalR.AspNet.nuspec
  12. +1 −1 {SignalR → SignalR.AspNet}/Routing/IncomingOnlyRouteConstraint.cs
  13. +3 −4 {SignalR → SignalR.AspNet}/Routing/PersistentRouteHandler.cs
  14. +1 −1 {SignalR → SignalR.AspNet}/Routing/RouteExtensions.cs
  15. +91 −0 SignalR.AspNet/SignalR.AspNet.csproj
  16. +4 −0 SignalR.AspNet/packages.config
  17. +1 −2 SignalR.Samples/App_Start/Startup.cs
  18. +4 −0 SignalR.Samples/SignalR.Samples.csproj
  19. +6 −0 SignalR.sln
  20. +0 −19 SignalR/AspNet/PreApplicationStart.cs
  21. +1 −2 SignalR/DefaultPersistentConnectionFactory.cs
  22. +2 −1 SignalR/Hubs/DefaultHubLocator.cs
  23. +2 −2 SignalR/Hubs/DefaultHubTypeResolver.cs
  24. +1 −2 SignalR/IPersistentConnectionFactory.cs
  25. +1 −1 SignalR/Infrastructure/DependencyResolver.cs
  26. +1 −1 SignalR/Properties/AssemblyInfo.cs
  27. +1 −15 SignalR/SignalR.csproj
  28. +0 −1 SignalR/packages.config
@@ -5,11 +5,11 @@
namespace SignalR.AspNet
{
- public class PersistentConnectionHandler : HttpTaskAsyncHandler
+ public class AspNetHost : HttpTaskAsyncHandler
{
private readonly PersistentConnection _connection;
- public PersistentConnectionHandler(PersistentConnection connection)
+ public AspNetHost(PersistentConnection connection)
{
_connection = connection;
}
@@ -74,6 +74,6 @@ public NameValueCollection Cookies
{
get;
private set;
- }
+ }
}
}
File renamed without changes.
@@ -0,0 +1,29 @@
+using System.Web;
+using Microsoft.Web.Infrastructure.DynamicModuleHelper;
+using SignalR.AspNet;
+using SignalR.Hubs;
+using SignalR.Infrastructure;
+using SignalR.Transports;
+
+[assembly: PreApplicationStartMethod(typeof(Bootstrapper), "Start")]
+
+namespace SignalR.AspNet
+{
+ public static class Bootstrapper
+ {
+ public static void Start()
+ {
+ DynamicModuleUtility.RegisterModule(typeof(HubModule));
+
+ // Replace defaults with asp.net implementations
+ var typeResolver = new BuildManagerTypeResolver();
+ var hubLocator = new BuildManagerTypeLocator();
+
+ DependencyResolver.Register(typeof(IHubTypeResolver), () => typeResolver);
+ DependencyResolver.Register(typeof(IHubLocator), () => hubLocator);
+
+
+ TransportManager.InitializeDefaultTransports();
+ }
+ }
+}
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Web.Compilation;
+using SignalR.Hubs;
+
+namespace SignalR.AspNet
+{
+ public class BuildManagerTypeLocator : IHubLocator
+ {
+ private readonly Lazy<IEnumerable<Type>> _hubs = new Lazy<IEnumerable<Type>>(GetAllHubs);
+
+ public IEnumerable<Type> GetHubs()
+ {
+ return _hubs.Value;
+ }
+
+ public static IEnumerable<Type> GetAllHubs()
+ {
+ return (from Assembly a in BuildManager.GetReferencedAssemblies()
+ where !a.GlobalAssemblyCache && !a.IsDynamic
+ from type in GetTypesSafe(a)
+ where typeof(IHub).IsAssignableFrom(type) && !type.IsAbstract
+ select type).ToList();
+ }
+
+ private static IEnumerable<Type> GetTypesSafe(Assembly a)
+ {
+ try
+ {
+ return a.GetTypes();
+ }
+ catch
+ {
+ return Enumerable.Empty<Type>();
+ }
+ }
+ }
+}
@@ -0,0 +1,14 @@
+using System;
+using System.Web.Compilation;
+using SignalR.Hubs;
+
+namespace SignalR.AspNet
+{
+ public class BuildManagerTypeResolver : DefaultHubTypeResolver
+ {
+ public override Type ResolveType(string hubName)
+ {
+ return base.ResolveType(hubName) ?? BuildManager.GetType(hubName, throwOnError: false);
+ }
+ }
+}
@@ -16,10 +16,10 @@ public void Init(HttpApplication app)
if (app.Request.AppRelativeCurrentExecutionFilePath.StartsWith(Url, StringComparison.OrdinalIgnoreCase) &&
!Path.GetExtension(app.Request.AppRelativeCurrentExecutionFilePath).Equals(".js", StringComparison.OrdinalIgnoreCase))
{
- var dispatcher = new HubDispatcher(VirtualPathUtility.ToAbsolute(Url));
- var handler = new PersistentConnectionHandler(dispatcher);
+ var connection = new HubDispatcher(VirtualPathUtility.ToAbsolute(Url));
+ var host = new AspNetHost(connection);
- app.Context.RemapHandler(handler);
+ app.Context.RemapHandler(host);
}
};
}
@@ -0,0 +1,6 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+[assembly: AssemblyTitle("SignalR.AspNet")]
+[assembly: AssemblyDescription("Asp.Net host for SignalR")]
+[assembly: AssemblyVersion("0.3.6.0")]
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<package>
+ <metadata>
+ <id>$id$</id>
+ <version>$version$</version>
+ <authors>$author$</authors>
+ <licenseUrl>https://github.com/SignalR/SignalR/blob/master/LICENSE.md</licenseUrl>
+ <projectUrl>https://github.com/SignalR/SignalR</projectUrl>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <description>$description$</description>
+ <dependencies>
+ <dependency id="SignalR.Server" version="0.3" />
+ </dependencies>
+ </metadata>
+</package>
@@ -1,7 +1,7 @@
using System.Web;
using System.Web.Routing;
-namespace SignalR.Routing
+namespace SignalR.AspNet.Routing
{
public class IncomingOnlyRouteConstraint : IRouteConstraint
{
@@ -1,10 +1,9 @@
using System;
using System.Web;
using System.Web.Routing;
-using SignalR.AspNet;
using SignalR.Infrastructure;
-namespace SignalR.Routing
+namespace SignalR.AspNet.Routing
{
public class PersistentRouteHandler : IRouteHandler
{
@@ -20,8 +19,8 @@ public PersistentRouteHandler(IDependencyResolver resolver, Type handlerType)
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var factory = (IPersistentConnectionFactory)_resolver.GetService(typeof(IPersistentConnectionFactory));
- PersistentConnection connection = factory.CreateInstance(requestContext, _handlerType);
- return new PersistentConnectionHandler(connection);
+ PersistentConnection connection = factory.CreateInstance(_handlerType);
+ return new AspNetHost(connection);
}
}
}
@@ -2,7 +2,7 @@
using System.Web.Routing;
using SignalR.Infrastructure;
-namespace SignalR.Routing
+namespace SignalR.AspNet.Routing
{
public static class RouteExtensions
{
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0E513AE2-BEA8-40CF-B9F2-102B351F2FB2}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SignalR.AspNet</RootNamespace>
+ <AssemblyName>SignalR.AspNet</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\SignalR\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <Private>True</Private>
+ <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\Common\CommonAssemblyInfo.cs">
+ <Link>Properties\CommonAssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="..\SignalR\TaskAsyncHelper.cs">
+ <Link>Infrastructure\TaskAsyncHelper.cs</Link>
+ </Compile>
+ <Compile Include="AspNetRequest.cs" />
+ <Compile Include="AspNetResponse.cs" />
+ <Compile Include="BuildManagerTypeLocator.cs" />
+ <Compile Include="BuildManagerTypeResolver.cs" />
+ <Compile Include="HttpTaskAsyncHandler.cs" />
+ <Compile Include="HubModule.cs" />
+ <Compile Include="Infrastructure\TaskWrapperAsyncResult.cs" />
+ <Compile Include="AspNetHost.cs" />
+ <Compile Include="Bootstrapper.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Routing\IncomingOnlyRouteConstraint.cs" />
+ <Compile Include="Routing\PersistentRouteHandler.cs" />
+ <Compile Include="Routing\RouteExtensions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\SignalR\SignalR.csproj">
+ <Project>{1B9A82C4-BCA1-4834-A33E-226F17BE070B}</Project>
+ <Name>SignalR</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ <None Include="Properties\SignalR.AspNet.nuspec">
+ <SubType>Designer</SubType>
+ </None>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
+</packages>
@@ -2,8 +2,8 @@
using System.Diagnostics;
using System.Threading;
using System.Web.Routing;
+using SignalR.AspNet.Routing;
using SignalR.Hubs;
-using SignalR.Routing;
using SignalR.Samples.App_Start;
using SignalR.Samples.Hubs.DemoHub;
@@ -15,7 +15,6 @@ public class Startup
{
public static void Start()
{
-
// Uncomment this for web farm support
//var cs = ConfigurationManager.ConnectionStrings["SignalR"].ConnectionString;
//var store = new PeerToPeerSQLSignalBusMessageStore(cs);
@@ -209,6 +209,10 @@
<Folder Include="App_Data\" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\SignalR.AspNet\SignalR.AspNet.csproj">
+ <Project>{0E513AE2-BEA8-40CF-B9F2-102B351F2FB2}</Project>
+ <Name>SignalR.AspNet</Name>
+ </ProjectReference>
<ProjectReference Include="..\SignalR.ScaleOut\SignalR.ScaleOut.csproj">
<Project>{32D16B36-970E-4CF2-B954-78CB1833CBC1}</Project>
<Name>SignalR.ScaleOut</Name>
View
@@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{1E4BA77C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Tests", "SignalR.Tests\SignalR.Tests.csproj", "{FBA09237-84CC-4383-BD12-CDF58E4020E8}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.AspNet", "SignalR.AspNet\SignalR.AspNet.csproj", "{0E513AE2-BEA8-40CF-B9F2-102B351F2FB2}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -43,6 +45,10 @@ Global
{FBA09237-84CC-4383-BD12-CDF58E4020E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBA09237-84CC-4383-BD12-CDF58E4020E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBA09237-84CC-4383-BD12-CDF58E4020E8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0E513AE2-BEA8-40CF-B9F2-102B351F2FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E513AE2-BEA8-40CF-B9F2-102B351F2FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0E513AE2-BEA8-40CF-B9F2-102B351F2FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0E513AE2-BEA8-40CF-B9F2-102B351F2FB2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1,19 +0,0 @@
-using System.Web;
-using Microsoft.Web.Infrastructure.DynamicModuleHelper;
-using SignalR.AspNet;
-using SignalR.Transports;
-
-[assembly: PreApplicationStartMethod(typeof(PreApplicationStart), "Start")]
-
-namespace SignalR.AspNet
-{
- public static class PreApplicationStart
- {
- public static void Start()
- {
- DynamicModuleUtility.RegisterModule(typeof(HubModule));
-
- TransportManager.InitializeDefaultTransports();
- }
- }
-}
@@ -1,12 +1,11 @@
using System;
-using System.Web.Routing;
using SignalR.Infrastructure;
namespace SignalR
{
public class DefaultPersistentConnectionFactory : IPersistentConnectionFactory
{
- public PersistentConnection CreateInstance(RequestContext requestContext, Type connectionType)
+ public PersistentConnection CreateInstance(Type connectionType)
{
if (connectionType == null)
{
@@ -17,7 +17,8 @@ public IEnumerable<Type> GetHubs()
public static IEnumerable<Type> GetAllHubs()
{
- return (from Assembly a in BuildManager.GetReferencedAssemblies()
+ // This only happens once and is cached for the lifetime of the appdomain
+ return (from Assembly a in AppDomain.CurrentDomain.GetAssemblies()
where !a.GlobalAssemblyCache && !a.IsDynamic
from type in GetTypesSafe(a)
where typeof(IHub).IsAssignableFrom(type) && !type.IsAbstract
@@ -66,7 +66,7 @@ private void AddCacheKey(string key, Type hubType)
}
}
- public Type ResolveType(string hubName)
+ public virtual Type ResolveType(string hubName)
{
Type type;
if (_hubCache.TryGetValue(hubName, out type))
@@ -75,7 +75,7 @@ public Type ResolveType(string hubName)
}
// Fallback to the build manager
- return BuildManager.GetType(hubName, throwOnError: true);
+ return null;
}
}
}
Oops, something went wrong.

0 comments on commit bb21706

Please sign in to comment.