Issue resolving Unity 2 container using NServiceBus 3 object builder

倾然丶 夕夏残阳落幕 提交于 2019-12-11 09:27:08

问题


I'm receiving the following error while using the NServiceBus 3.0.0 beta 2 pre-release object builder for Unity 2. As far as I have been able to trace, it appears to be a problem with the CommonObjectBuilder in the AutowireEnabledInjectionProperty builder.

Configuration for NSB is as follows:

public class NServiceBusContainerExtension : UnityContainerExtension
{
    protected override void Initialize()
    {
        var busConfig = NServiceBus.Configure.WithWeb()
            .Log4Net()
            .UnityBuilder(Container)
            .MsmqTransport()
                .IsTransactional(true)
                .PurgeOnStartup(false)
            .XmlSerializer()
            .UnicastBus();

        var bus = busConfig
                    .CreateBus()
                    .Start();

        Container.RegisterType<IPublisher, NServiceBusPublisher>(new InjectionConstructor(bus));
    }
}

Error:

[ArgumentNullException: Value cannot be null.
Parameter name: typeToCreate]
   Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(Object argumentValue, String argumentName) +55
   NServiceBus.ObjectBuilder.Unity.AutowireEnabledInjectionProperty.AddPolicies(Type typeToCreate, Type implementationType, String name, IPolicyList policies) +87
   Microsoft.Practices.Unity.UnityContainer.RegisterType(Type from, Type to, String name, LifetimeManager lifetimeManager, InjectionMember[] injectionMembers) +405
   Microsoft.Practices.Unity.InjectedMembers.ConfigureInjectionFor(Type serviceType, Type implementationType, String name, InjectionMember[] injectionMembers) +66
   Microsoft.Practices.Unity.InjectedMembers.ConfigureInjectionFor(Type typeToInject, InjectionMember[] injectionMembers) +22
   NServiceBus.ObjectBuilder.Unity.ConfigureComponentAdapter.ConfigureProperty(String name, Object value) +325
   NServiceBus.ObjectBuilder.Unity.UnityObjectBuilder.ConfigureProperty(Type concreteComponent, String property, Object value) +338
   NServiceBus.ObjectBuilder.Common.ComponentConfig.NServiceBus.ObjectBuilder.IComponentConfig.ConfigureProperty(String name, Object value) +120
   NServiceBus.ObjectBuilder.Common.ComponentConfig`1.NServiceBus.ObjectBuilder.IComponentConfig<T>.ConfigureProperty(Expression`1 property, Object value) +266
   NServiceBus.ObjectBuilder.Common.Config.ConfigureCommon.With(Configure config, IContainer container) +633
   NServiceBus.ConfigureUnityBuilder.UnityBuilder(Configure config, IUnityContainer container) +112

回答1:


You need to register all new types in the container before calling .CreateBus().




回答2:


I would like to have accepted Udi's answer because, well, he's the man. However, I was never able to get the Unity 2 builder to work despite attempting to register every type that we needed.

After a week or so, I ended up going back to using the DefaultBuilder, passing in our prebuilt Unity container into a ServiceLocator, and registering the IServiceLocator as a singleton to NSB's default builder. It worked out quite well.



来源:https://stackoverflow.com/questions/8651005/issue-resolving-unity-2-container-using-nservicebus-3-object-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!