3
我試圖注入一個對象到我的傳奇。使用以下端點,當消息到達saga的句柄方法時,該屬性爲null。NserviceBus屬性注入
端點:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantToRunAtStartup
{
public void Run()
{
IOrderRepository orderRepository = new OrderRepository();
Configure.Instance.Configurer.ConfigureProperty<CreateOrderSaga>(x => x.OrderRepository, orderRepository);
}
// stop method removed
}
在app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig
InputQueue="Fulfilment.CreateOrder.OrderRecievedMessage"
ErrorQueue="error"
NumberOfWorkerThreads="1"
MaxRetries="3"
/>
<UnicastBusConfig
DistributorControlAddress=""
DistributorDataAddress="">
<MessageEndpointMappings>
<add Messages="NServiceBus.Saga.TimeoutMessage, NServiceBus" Endpoint="timeoutmanager" />
</MessageEndpointMappings>
</UnicastBusConfig>
</configuration>
和我佐賀接受郵件如下
空引用厚望會嘗試調用時拋出SaveOrder()。我是否正確配置了依賴注入?
輝煌。謝謝安德烈亞斯。那就是訣竅。 – Adam
現在有一個簡短的形式,只是:Configure.Component(生命週期); –