Issues with NServiceBus and AutoFac after upgrading to 5.0

328 views
Skip to first unread message

Ole Albers

unread,
Jan 21, 2015, 11:24:47 AM1/21/15
to particula...@googlegroups.com
Helpful information to include
Product name:
Version:
Stacktrace:
Description:


Hi there. I just upgraded to NServicebus 5.0 (was 4.6 before) and now I receive an error inside my controller using NServiceBus:.

None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Nop.Web.Controllers.ShoppingCartController' can be invoked with the available services and parameters:
Cannot resolve parameter 'NServiceBus.IBus bus' of constructor 'Void .ctor(NServiceBus.IBus,...)


This is my configuration:
 public static void Init(ILifetimeScope scope)
       
{
var configuration = new BusConfiguration();
            configuration
.EndpointName(ConfigurationManager.AppSettings["ServiceBusEndpointName"]);
            configuration
.UseTransport<MsmqTransport>();
            configuration
.UseSerialization<JsonSerializer>();
            configuration
.UsePersistence<RavenDBPersistence>();
            configuration
.DisableFeature<Sagas>();
            configuration
.Transactions().Enable();
            configuration
.AssembliesToScan(AllAssemblies
               
.Matching("Nop.Services.dll")
               
.And("Messages.dll")
               
.And("Partner.Pricing.Messages.dll")
               
.And("Partner.Pricing.Infrastructure.dll"));
            configuration
.UseContainer<AutofacBuilder>();
            configuration
.PurgeOnStartup(false);


           
var bus  = Bus.Create(configuration);
            bus
.Start();
           
var newBuilder = new ContainerBuilder();

         
//   newBuilder.RegisterInstance(bus);
            newBuilder
.Update(Singleton<IContainer>.Instance);
}


As you can see, "UseContainer<AutofacBuilder>" is already included.

This was my (working) 4.6 configuration:
 public static void Init(ILifetimeScope scope)
       
{
           
Configure.Transactions.Enable();
           
Configure.Serialization.Json();
           
Configure.Features.Disable<Sagas>();


           
var bus =
             
Configure.With(
               
AllAssemblies.Matching("Nop.Services.dll")
                   
.And("Messages.dll")
                   
.And("Partner.Pricing.Messages.dll")
                   
.And("Partner.Pricing.Infrastructure.dll"))
               
.DefineEndpointName(ConfigurationManager.AppSettings["ServiceBusEndpointName"])
               
.AutofacBuilder(scope)
               
.Log4Net<RollingFileAppender>(x => x.File = ConfigurationManager.AppSettings["ServiceBusLog"])
               
.RavenSubscriptionStorage()
               
.UseTransport<Msmq>()
               
.PurgeOnStartup(false)
               
.UnicastBus()
               
.RunHandlersUnderIncomingPrincipal(false)
               
.CreateBus()
               
.Start(() => Configure.Instance.ForInstallationOn<Windows>()
                   
.Install());


           
var newBuilder = new ContainerBuilder();
            newBuilder
.RegisterInstance(bus);


            newBuilder
.Update(Singleton<IContainer>.Instance);        
       
}



Thanks


Szymon Pobiega

unread,
Jan 22, 2015, 12:12:00 AM1/22/15
to particula...@googlegroups.com
Hey

I am not an expert on Autofac, but since you use RegisterInstance<T> without .As<SomeType>, in the V5 code it will probably register the instance as IStartableBus, not as IBus. Again, not sure if Autofac is smart enough to figure out that it can inject this instance to a component requiring IBus. In the V4 code you register the result of the .Start() method (IBus, not IStartableBus) so it works.

Szymon

--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, 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/c218b2a4-e987-4029-a5f1-040361dd9ea9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Öhlund

unread,
Jan 22, 2015, 2:30:58 AM1/22/15
to particula...@googlegroups.com
Since NServiceBus already registers the bus in the container for you why do you need to register it again?

Ole Albers

unread,
Jan 22, 2015, 3:28:42 AM1/22/15
to particula...@googlegroups.com
To be honest, I do not really know what I am doing there :) Just try to make existing code from 4.6 work in 5.0 (Code was part of an external package)

--
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/zyTKtV5Dmio/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.

Ole Albers

unread,
Jan 22, 2015, 3:34:21 AM1/22/15
to particula...@googlegroups.com
So your suggestion is to remove/change what exactly?

Andreas Öhlund

unread,
Jan 22, 2015, 4:50:07 AM1/22/15
to particula...@googlegroups.com
I think you can remove the:

  var newBuilder = new ContainerBuilder();

         
//   newBuilder.RegisterInstance(bus);
            newBuilder
.Update(Singleton<IContainer>.Instance); 

part.

Szymon Pobiega

unread,
Jan 22, 2015, 5:05:27 AM1/22/15
to particula...@googlegroups.com
Yeah, but then you need to pass the container into the UseContainer method:

configuration.UseContainer<AutofacBuilder>();

I think that this difference between your V4 and V5 code caused the bus to not be registered

Szymon

Ole Albers

unread,
Jan 22, 2015, 9:18:19 AM1/22/15
to particula...@googlegroups.com
Sorry if I sound annoying: But can you tell me what to do exactly? I removed the complete part from the ContainerBuilder. Nonetheless the Error still exists.

Andreas Öhlund

unread,
Jan 22, 2015, 9:29:53 AM1/22/15
to particula...@googlegroups.com
Change your "UseContainer" line to:

config.UseContainer<AutofacBuilder>(c=>c.ExistingLifetimeScope(scope));

this tells the autofac builder to use your existing scope instead of creating a new one.

Hope this helps!

Reply all
Reply to author
Forward
0 new messages