-
Notifications
You must be signed in to change notification settings - Fork 8
Setup Dependencies (Composition Root)
Mitch Ferrer edited this page Mar 5, 2015
·
1 revision
To ensure the framework is extensible and allow for the consumer to override or decorate the behavior of the framework, we require a bit of setup. We use a thin DI container abstraction with a few implementations out of the box it can be found here.
// Create your container, here we are using SimpleInjector.
var container = new SimpleInjectorContainer(new Container());
ContainerRegistry.DefaultContainer = container;
// Wire-up the helper services services, here is your opportunity to tweak behavior.
container.Bind<ISignalRSerializer, CamelCaseSignalRSerializer>(true);
container.Bind<IMessagingContext, SignalRMessagingContext>(true);
container.Bind<ISignalRConnectionLookupService, SignalRConnectionLookupService>(true);
// Groups allow you to target broadcasts at a subset of your users.
var groupService = new SignalRGroupService();
container.RegisterSingleton<IGroupJoinService>(groupService);
container.RegisterSingleton<IGroupLeaveService>(groupService);
container.RegisterSingleton<IGroupLookupService>(groupService);
// You will need to implement a Group Registrar for the event hub to put your users into groups automatically upon connection.
container.Bind<ISignalRGroupRegistrar, GroupRegistrar>(true);
// You will register your handler's in the handler repository so that the Event Hub can invoke them.
var handlerRepository = new DIHandlerRepository(container);
container.RegisterSingleton<IHandlerRepository>(handlerRepository);
// Example Registration
repository.AddHandler<UserListHandler>(UserEvents.ListRequest);