コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        public void Configuration(IAppBuilder app)
        {
            // 有关如何配置应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkID=316888

            var kernel = new StandardKernel();

            // SignalR Hub DP resolver
            var signalRDependencyResolver = new NInjectSignalRDependencyResolver(kernel);

            // Register hub connection context
            kernel.Bind(typeof(IHubConnectionContext <dynamic>)).
            ToMethod(context =>
                     signalRDependencyResolver.Resolve <IConnectionManager>().
                     GetHubContext <BroadCastHub>().Clients).
            WhenInjectedInto <IBroadCastService>();

            // Register message broadcaster class
            kernel.Bind <IBroadCastService>().
            ToConstant <BroadCastService>(new BroadCastService());

            // IBroadcast DP resolver
            GlobalConfiguration.Configuration.DependencyResolver = new NInjectDependencyResolver(kernel);

            app.Map("/signalr", map =>
            {
                map.UseCors(CorsOptions.AllowAll);
                map.RunSignalR(new HubConfiguration()
                {
                    EnableDetailedErrors    = true,
                    EnableJavaScriptProxies = false,
                    Resolver = signalRDependencyResolver
                });
            });
        }
コード例 #2
0
        /// <summary>
        /// Configuration value
        /// </summary>
        /// <param name="app">IAppBuilder value</param>
        public void Configuration(IAppBuilder app)
        {
            var kernel = new StandardKernel();

            // SignalR Hub DP resolver
            var signalRDependencyResolver = new NInjectSignalRDependencyResolver(kernel);

            // Register hub connection context
            kernel.Bind(typeof(IHubConnectionContext <dynamic>)).
            ToMethod(context =>
                     signalRDependencyResolver.Resolve <IConnectionManager>().
                     GetHubContext <BroadCastHub>().Clients).
            WhenInjectedInto <IBroadCast>();

            // Register message broadcaster class
            kernel.Bind <IBroadCast>().
            ToConstant <BroadCaster>(new BroadCaster());

            // IBroadcast DP resolver
            GlobalConfiguration.Configuration.DependencyResolver = new NInjectDependencyResolver(kernel);

            GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null; // Unlimited incoming message size

            app.Map("/signalr", map =>
            {
                map.UseCors(CorsOptions.AllowAll);
                map.RunSignalR(new HubConfiguration()
                {
                    EnableDetailedErrors = true,
                    Resolver             = signalRDependencyResolver,
                });
            });
        }