Skip to content

Commit

Permalink
Remove System.Web reference from SignalR.Server
Browse files Browse the repository at this point in the history
- 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
davidfowl committed Dec 29, 2011
1 parent 31bf653 commit bb21706
Show file tree
Hide file tree
Showing 28 changed files with 230 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public NameValueCollection Cookies
{
get;
private set;
}
}
}
}
File renamed without changes.
29 changes: 29 additions & 0 deletions SignalR.AspNet/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
40 changes: 40 additions & 0 deletions SignalR.AspNet/BuildManagerTypeLocator.cs
Original file line number Diff line number Diff line change
@@ -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>();
}
}
}
}
14 changes: 14 additions & 0 deletions SignalR.AspNet/BuildManagerTypeResolver.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
File renamed without changes.
6 changes: 3 additions & 3 deletions SignalR/AspNet/HubModule.cs → SignalR.AspNet/HubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions SignalR.AspNet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
15 changes: 15 additions & 0 deletions SignalR.AspNet/Properties/SignalR.AspNet.nuspec
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Web;
using System.Web.Routing;

namespace SignalR.Routing
namespace SignalR.AspNet.Routing
{
public class IncomingOnlyRouteConstraint : IRouteConstraint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Web.Routing;
using SignalR.Infrastructure;

namespace SignalR.Routing
namespace SignalR.AspNet.Routing
{
public static class RouteExtensions
{
Expand Down
91 changes: 91 additions & 0 deletions SignalR.AspNet/SignalR.AspNet.csproj
Original file line number Diff line number Diff line change
@@ -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>
4 changes: 4 additions & 0 deletions SignalR.AspNet/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
</packages>
3 changes: 1 addition & 2 deletions SignalR.Samples/App_Start/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions SignalR.Samples/SignalR.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions SignalR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 0 additions & 19 deletions SignalR/AspNet/PreApplicationStart.cs

This file was deleted.

3 changes: 1 addition & 2 deletions SignalR/DefaultPersistentConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion SignalR/Hubs/DefaultHubLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions SignalR/Hubs/DefaultHubTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -75,7 +75,7 @@ public Type ResolveType(string hubName)
}

// Fallback to the build manager
return BuildManager.GetType(hubName, throwOnError: true);
return null;
}
}
}
Loading

0 comments on commit bb21706

Please sign in to comment.