Message Handlers not registered in container (Autofac)

342 views
Skip to first unread message

Pabich Pawel

unread,
Sep 30, 2015, 7:51:20 PM9/30/15
to Particular Software
Hi,

It looks like NSB can discover my handlers but it it does not register them in the container. My understanding is that NSB should discover and  register them for me: http://docs.particular.net/nservicebus/containers/.

Message: "The requested service 'TestHandler'  has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency"
Stack Trace: "at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType)
   at NServiceBus.ObjectBuilder.Autofac.AutofacObjectBuilder.Build(Type typeToBuild) in c:\BuildAgent\work\cd937cd0783294f6\src\NServiceBus.Autofac\AutofacObjectBuilder.cs:line 37
   at NServiceBus.ObjectBuilder.Common.CommonObjectBuilder.Build(Type typeToBuild)
   at NServiceBus.LoadHandlersBehavior.Invoke(IncomingContext context, Action next)
   at NServiceBus.BehaviorChain`1.InvokeNext(T context)"
Code:     configuration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));

When I register the handler manually then everything works fine.
Any ideas how can be happening here?

Helpful information to include
  <package id="NServiceBus" version="5.2.6" targetFramework="net45" />
  <package id="NServiceBus.Autofac" version="5.0.0" targetFramework="net45" />
  <package id="NServiceBus.Serilog" version="2.0.1.1" targetFramework="net45" />
  <package id="NServiceBus.SqlServer" version="2.2.0" targetFramework="net45" />

Thanks

Pawel

simon.cropp

unread,
Sep 30, 2015, 10:10:36 PM9/30/15
to Particular Software
Are you doing custom assembly scanning?

Can you share a repro?

Pabich Pawel

unread,
Sep 30, 2015, 11:28:59 PM9/30/15
to particula...@googlegroups.com
Nope, I will try to repro.

On 1 October 2015 at 12:10, simon.cropp <simon...@particular.net> wrote:
Are you doing custom assembly scanning?

Can you share a repro?

--
You received this message because you are subscribed to a topic in the Google Groups "Particular Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/particularsoftware/rp-a9ttKVEA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.
To view this discussion on the web visit https://groups.google.com/d/msgid/particularsoftware/ec438240-a677-4d9d-b95d-b7ccb4e400c6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

simon.cropp

unread,
Sep 30, 2015, 11:49:08 PM9/30/15
to Particular Software
Are you doing anything special with TestHandler? or perhaps any container customisation?

Pabich Pawel

unread,
Sep 30, 2015, 11:58:53 PM9/30/15
to particula...@googlegroups.com
Not really.
This is the config:

    var configuration = new BusConfiguration();
            configuration.CustomConfigurationSource(new ConfigurationProvider(_queueName));
            configuration.EndpointName(_queueName);
            configuration.UseTransport<SqlServerTransport>()
                            .DisableCallbackReceiver()
                            .ConnectionString(connectionString);
            configuration.UseSerialization<JsonSerializer>();

            configuration.UsePersistence<InMemoryPersistence>();
            configuration.Transactions().DisableDistributedTransactions();

            LogManager.Use<SerilogFactory>();

    configuration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));

            Bus.Create(configuration).Start();

On 1 October 2015 at 13:49, simon.cropp <simon...@particular.net> wrote:
Are you doing anything special with TestHandler? or perhaps any container customisation?

--
You received this message because you are subscribed to a topic in the Google Groups "Particular Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/particularsoftware/rp-a9ttKVEA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.

simon.cropp

unread,
Oct 1, 2015, 12:02:12 AM10/1/15
to Particular Software
yep but what code creates container ?

Pabich Pawel

unread,
Oct 1, 2015, 12:07:33 AM10/1/15
to particula...@googlegroups.com
var builder = new ContainerBuilder();

            builder.RegisterModule<Module1>();
            builder.RegisterModule<Module2>();
            builder.RegisterModule<ModuleN>();


            _container = builder.Build();

and then I pass it to the code that configures the bus.

On 1 October 2015 at 14:02, simon.cropp <simon...@particular.net> wrote:
yep but what code creates container ?

--
You received this message because you are subscribed to a topic in the Google Groups "Particular Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/particularsoftware/rp-a9ttKVEA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.

simon.cropp

unread,
Oct 1, 2015, 11:55:28 PM10/1/15
to Particular Software
Ok then back to can you provide a way to reproduce it so i can debug into it?

Pabich Pawel

unread,
Oct 2, 2015, 8:09:55 AM10/2/15
to particula...@googlegroups.com
I will try to come up with something in week or so

On 2 October 2015 at 13:55, simon.cropp <simon...@particular.net> wrote:
Ok then back to can you provide a way to reproduce it so i can debug into it?

--
You received this message because you are subscribed to a topic in the Google Groups "Particular Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/particularsoftware/rp-a9ttKVEA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.
Reply all
Reply to author
Forward
0 new messages