0
這裏是我的參數:NServiceBus單位
- 使用默認的建設者
- 在內部ORM上的SQL Server
- 多租戶的頂部簡單NServiceBus佐賀實現 - 我有2個ASP.NET MVC 4個在同一個網站上運行的域,每一個都有自己的數據庫
我們配置使用靜態方法,我們的ORM像這樣:
public class EndpointConfig: IConfigureThisEndpoint, IWantCustomInitialization {
public void Init() {
var bus = Configure.With()
.AutofacBuilder()
.UnicastBus().LoadMessageHandlers().DoNotAutoSubscribe()
.XmlSerializer()
.MsmqTransport().IsTransactional(true).PurgeOnStartup(false)
.MsmqSubscriptionStorage()
.Sagas().RavenSagaPersister().InstallRavenIfNeeded()
.UseInMemoryTimeoutPersister()
.CreateBus()
.Start();
SlenderConfiguration.Init(bus);
}
}
public class SlenderCofnigruation {
private static ORMScope scope { get; set; }
public static void Init(IBus bus)
{
ORMConfig.GetScope =() =>
{
var environment = "dev";
if (bus.CurrentMessageContext.Headers.ContainsKey("Environment"))
environment = bus.CurrentMessageContext.Headers["Environment"];
if (scope == null)
scope = new SlenderScope(ConfigurationManager.ConnectionStrings[environment].ConnectionString);
return scope;
};
}
}
這在我們的單租戶Beta版環境中可以正常工作 - 因爲對於給定的部署,環境頭始終是相同的,所以可以重新使用該靜態範圍。
這是我的理解,這不會工作的上述multitenant情況,因爲NServiceBus將跨消息重用線程。然後相同的範圍將被使用,導致問題如果消息意圖用於不同的環境。
我想我要的是每個消息一個範圍,但我真的不知道怎麼去那裏。
我見過Unit Of Work Implementation for RavenDB,和全雙工樣品中工作落實的單位,但我不知道這是正確的道路。
我也看到了DependencyLifecycle枚舉,但我不知道我怎麼可以用它來解決給我不得不成立GetScope FUNC方式的範圍。
很顯然,我不知道是怎麼回事。有什麼建議麼?