0

I'm using Simple Injector for IoC and Rebus, service bus, to dispatch events saved in multiple queues (topic). Rebus needs to be configured with a new SimpleInjectorContainerAdapter for each queue.

var bus = Configure.With(new SimpleInjectorContainerAdapter(container))

In this configuration phase is not possible to pass the same instance of Simple injector container neither the same instance of container adapter (the container rises an error of multiple registration of IBus).

I'm also using SignalR as one of the events ' handlers to dispatch events to the clients.
Following this SignalR configuration tutorial I set up several hub and relative event notifier (one for each bounded context in the application).
Using the classical singleton pattern, as shown in the tutorial example, is easy to pass the same instance of notifier to the various instances of containers:
container.RegisterSingleton(Finishing.Notification.Notifier.Instance);

Now I would like to delegate the instance creation to the Simple Injector container (only one), so I started to follow this tutorial:

        container.RegisterSingleton<Finishing.Notification.Notifier>();
        container.Register(() => GlobalHost.ConnectionManager.GetHubContext<Finishing.Notification.NotificationHub>().Clients);

The issue is that, in this way, I will have n instance of notifier one for each container instance (deeply regrettable).

I know that I can solve this using a master container as Abstract Factory, but I'm looking for a more specific solution.
Thanks.

4
  • 1
    Did you try override existing registrations to resolve the original error multiple registration of IBus?
    – qujck
    Nov 7, 2016 at 15:37
  • Can I ask, why specifically you would like to avoid the service locater pattern? It would seem like that would be a good fit for your requirement.
    – ravi
    Nov 8, 2016 at 4:53
  • @ravi I'd like to avoid service locator because I know it is an anti-pattern
    – ilcorvo
    Nov 9, 2016 at 10:48
  • @ilcorvo, you will have to think about it in the context of your solution. It is not a anti-pattern in all scenarios.
    – ravi
    Nov 10, 2016 at 0:19

1 Answer 1

0

Now I would like to delegate the instance creation to the Simple Injector containers

(...)

The issue is this way I will have n instance of notifier one for each container instance.

So you would like for each container to create the singleton instance, but it is a problem that each container holds an instance of the singleton... isn't that a contradiction?

2
  • Probably I was not clear: I definitely don’t like to have multiple instances of the notifier classes, so I'm asking for a tips to pass instance from the master container to the child containers, avoiding service locator pattern.
    – ilcorvo
    Nov 7, 2016 at 13:50
  • Ah, then I get it. So it's not really related to Rebus, it's more of a SimpleInjector question?
    – mookid8000
    Nov 7, 2016 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.