Skip to content

hazzik/SignalRWindsorFacility

Repository files navigation

SignalRWindsorFacility

SignalRWindsorFacility adds ability to call client side services just with injected interface

Why?

  1. It is testable. You are using these interfaces as any normal .NET interface
  2. It supports intellisense

Example

  1. Define contract for client-side service

    public interface IChat
    {
        void AddMessage(string msg);
    }
  2. Register IChat as client-side service associated with ChatHub

    public class DefaultInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.AddFacility<ClientServiceFacility>();
    
            container.Register(
                Component.For<IChat>().AsClientService().WithHub<ChatHub>());
        }
    }
  3. Write your client-side logic

    (function ($) {
        $.extend($.connection.chatHub.client, {
            addMessage: function(msg) {
                alert(msg);
            }
        });
        $.connection.hub.start();
    })(jQuery);  
  4. Inject IChat anywhere and call its methods as normal

    public class HomeController : Controller
    {
        readonly IChat chat;
    
        public HomeController(IChat chat)
        {
            this.chat = chat;
        }
    
        public ActionResult Index()
        {
            chat.AddMessage("Hello");
    
            return View();
        }
    }

About

SignalR Windsor Facility

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published