1
votes

I'm trying out Rebus with the (external) timeoutservice.

The TimeoutService correctly sends back a TimeoutReply. Then the subscriber logs an error that the TimeoutReplyHandler cannot be invoked.

I'm using Autofac for dependency injection and use the following configuration to register the Handlers:

ContainerBuilder builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
.Where(t => t.GetInterfaces().Any(i => i.IsAssignableFrom(typeof(IHandleMessages))))
.AsImplementedInterfaces()
.InstancePerDependency()
.PropertiesAutowired();

var container = builder.Build();
adapter = new AutofacContainerAdapter(container);

The following exception is thrown:

Autofac.Core.DependencyResolutionException: None of the constructors found with 'Public binding flags' on type 'Rebus.Bus.TimeoutReplyHandler' can be invoked wi th the available services and parameters: Cannot resolve parameter 'Rebus.Bus.IHandleDeferredMessage handleDeferredMessage ' of constructor 'Void .ctor(Rebus.Bus.IHandleDeferredMessage)'. at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IC omponentContext context, IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifeti meScope currentOperationScope, IComponentRegistration registration, IEnumerable` 1 parameters)

The TimeoutReply is handled by the internal class TimeoutReplyHandler, which needs an IHandleDeferredMessage in the ctor. The internal class DeferredMessageReDispatcher implements IHandleDeferredMessage and needs the IBus in the ctor. IHandleDeferredMessage is also internal scoped.

How should I configure the autofac container to handle TimeoutReply?

1

1 Answers

1
votes

The TimeoutReplyHandler is newed up by Rebus when an incoming TimeoutReply needs to be handled - it is not supposed to be in your container :)

I am guessing that you have some Autofac assembly scanning that happens to come by the TimeoutReplyHandler, thus ending up registering one of Rebus' internal types as if it was your handler.

See if you can remove the registration from the container, possibly by registering only types from your own assemblies.