/// <summary> /// Returns the JavaScript proxy for any hubs found in any assemblies loaded into the AppDomain /// </summary> /// <param name="signalRUrlPath">The service URL used by the connection. Defaults to "/signalr". When created dynamically this would generate at the running address, for example if you had an IIS app called "MyApp" it would generate "http://localhost:port/MyApp/signalr".</param> /// <param name="metaData">An array of lines to prepend into the file. This can be useful if you want to specify a path in your build system to a dependency such as jQuery</param> /// <returns>JavaScript proxy code</returns> public string Generate(string signalRUrlPath = "/signalr", params string[] metaData) { var generator = new DefaultJavaScriptProxyGenerator(new DefaultDependencyResolver()); var js = generator.GenerateProxy(signalRUrlPath, true); var jsToOutput = TrimComments(js); jsToOutput = PrependMetaData(jsToOutput, metaData); return(jsToOutput); }
public void MinifiesScriptUsingConfiguredMinifier() { // Arrange var hubManager = new Mock<IHubManager>(); var jsMinifier = new Mock<IJavaScriptMinifier>(); jsMinifier.Setup(m => m.Minify(It.IsAny<string>())) .Returns<string>(source => "it was minified"); var generator = new DefaultJavaScriptProxyGenerator(hubManager.Object, jsMinifier.Object); // Act var js = generator.GenerateProxy("http://localhost/testhub"); // Assert Assert.Equal("it was minified", js); }
public void MinifiesScriptUsingConfiguredMinifier() { // Arrange var hubManager = new Mock <IHubManager>(); var jsMinifier = new Mock <IJavaScriptMinifier>(); jsMinifier.Setup(m => m.Minify(It.IsAny <string>())) .Returns <string>(source => "it was minified"); var generator = new DefaultJavaScriptProxyGenerator(hubManager.Object, jsMinifier.Object); // Act var js = generator.GenerateProxy("http://localhost/testhub"); // Assert Assert.Equal("it was minified", js); }
internal DefaultDependencyResolver() { var store = new Lazy <InProcessMessageStore>(() => new InProcessMessageStore()); Register(typeof(IMessageStore), () => store.Value); var serializer = new JsonConvertAdapter(); Register(typeof(IJsonSerializer), () => serializer); Register(typeof(IActionResolver), () => new DefaultActionResolver()); Register(typeof(IHubActivator), () => new DefaultHubActivator()); Register(typeof(IHubFactory), () => new DefaultHubFactory()); var hubLocator = new DefaultHubLocator(); Register(typeof(IHubLocator), () => hubLocator); var hubTypeResolver = new Lazy <DefaultHubTypeResolver>(() => new DefaultHubTypeResolver()); Register(typeof(IHubTypeResolver), () => hubTypeResolver.Value); var signalBus = new InProcessSignalBus(); Register(typeof(ISignalBus), () => signalBus); var pesistentConnectionFactory = new DefaultPersistentConnectionFactory(); Register(typeof(IPersistentConnectionFactory), () => pesistentConnectionFactory); var minifier = new NullJavaScriptMinifier(); var proxyGenerator = new DefaultJavaScriptProxyGenerator(hubLocator, (IJavaScriptMinifier)GetService(typeof(IJavaScriptMinifier)) ?? minifier); Register(typeof(IJavaScriptProxyGenerator), () => proxyGenerator); var connectionIdFactory = new GuidConnectionIdFactory(); Register(typeof(IConnectionIdFactory), () => connectionIdFactory); Register(typeof(ITransportManager), () => TransportManager.Default); var signaler = new Lazy <Signaler>(() => new Signaler(DependencyResolver.Resolve <ISignalBus>())); Register(typeof(Signaler), () => signaler.Value); }
internal DefaultDependencyResolver() { var store = new Lazy <InProcessMessageStore>(() => new InProcessMessageStore()); Register(typeof(IMessageStore), () => store.Value); var serialzier = new JavaScriptSerializerAdapter(new JavaScriptSerializer { MaxJsonLength = 30 * 1024 * 1024 }); Register(typeof(IJsonStringifier), () => serialzier); Register(typeof(IActionResolver), () => new DefaultActionResolver()); Register(typeof(IHubActivator), () => new DefaultHubActivator()); Register(typeof(IHubFactory), () => new DefaultHubFactory()); var hubLocator = new DefaultHubLocator(); Register(typeof(IHubLocator), () => hubLocator); var signalBus = new InProcessSignalBus(); Register(typeof(ISignalBus), () => signalBus); var pesistentConnectionFactory = new DefaultPersistentConnectionFactory(); Register(typeof(IPersistentConnectionFactory), () => pesistentConnectionFactory); var minifier = new NullJavaScriptMinifier(); var proxyGenerator = new DefaultJavaScriptProxyGenerator(hubLocator, (IJavaScriptMinifier)GetService(typeof(IJavaScriptMinifier)) ?? minifier); Register(typeof(IJavaScriptProxyGenerator), () => proxyGenerator); var clientIdFactory = new GuidClientIdFactory(); Register(typeof(IClientIdFactory), () => clientIdFactory); }
public CustomProxyGenerator() { _generator = new DefaultJavaScriptProxyGenerator( GlobalHost.DependencyResolver ); }