Q:

Rebus Servicebus with Unity as IoC

I have a couple of newbie starting problems with Rebus. All the nice samples in the Rebus ReadMe file uses Windsor Castle, but I don't have that option; instead I must use Unity.
My first challenge was to find a suitable adapter for the Unity IoC Container, as the example states:
var someContainerAdapter =
    new AdapterForMyFavoriteIocContainer(myFavoriteIocContainer);

I finally found some code here that seems to do the job, but perhaps a better container exist, as I have to implement the IContainerAdapter interface myself (I wonder if that is needed...).
But I can live with that...
My next problem is worse and I haven't found out yet. In the Rebus Getting started-example the following is used to add a handler to  the IoC container:
container.Register(
    Component.For<IHandleMessages<DateTime>>()
    .ImplementedBy<PrintDateTime>());

This above is Windsor Castle syntax and I don't know how the Unity syntax should be for the same action. So I need some help here. A suggestion would be if I could get a reference to a small solution that works with Unity. 

A:

My suggestion is to use Rebus.Unity, which is a ready-to-use Unity container adapter for Rebus, made by one the awesome Rebus contributors.
There's a NuGet package for it, so you could just install-package Rebus.Unity (or whichever way is your preferred way of adding NuGet packages to your project).
Now, in order to register handlers with Unity, you should be aware of the fact that Unity behaves differently than all the other containers out there regarding ResolveAll behavior (at least the ones that I know about), which requires that all of your handlers are registered as named registrations.
I don't remember the exact Unity syntax to do this, but I think it looks somewhat like this:
container.RegisterType<IHandleMessages<SomeMessage>, MyMessageHandler>("id");

in order to register MyMessageHandler as a handler of SomeMessage. There's several other overloads of the various registration functions, so you should be able to find one that fits your needs - but keep in mind that with Unity, since Rebus does a ResolveAll, you must always register handlers with a key/id.

A:

Using unity with Rebus require me to register IHandleMessages the following types

SubscriptionMessage
IRebusControlMessage
object

...since the IContainerAdapter.GetHandlerInstancesFor< T > is called with the above types.
And Im afraid that in not the idea.
I cannot make unity resolve a type using an interface as Key without also specifying the type implementing the interface.
It would be great if one the awesome Rebus contributors could post an example that use Unity.

