2011-06-25 56 views
1

我正在嘗試讓AsyncController在OrchardProject中工作。我正在使用的當前版本是2.2.4.9.0。Autofac,OrchardProject和AsyncControllers

我已經有2人眼球我的代碼:http://www.pastie.org/2117952(AsyncController),它在正常的MVC3香草應用程序中正常工作。

基本上,我可以路由到IndexCompleted,但我不能路由到索引。我打算假設我在整個項目的Autofac配置中缺少一些東西。

我認爲配置是在Global.asax:爲AsyncControllers,或者如果有http://pastie.org/2118008

我正在尋找的是,如果這是實現autofac正確的方式引導一些別的東西/某處我需要實現/初始化/等。

〜丹

+0

什麼版本的Autofac的是什麼? –

+0

Peter,它是2.2.4.9.0 – Dregalia

+0

好的,從問題來看不清楚這是一個Orchard版本號還是一個Autofac編號:) –

回答

2

果園似乎註冊了自己的IActionInvoker,名爲Orchard.Mvc.Filters.FilterResolvingActionInvoker

此課程來自ControllerActionInvoker。猜測,爲了支持異步操作,它應該從AsyncControllerActionInvoker派生。

希望這會有所幫助!

尼克

0

的Autofac設置看起來不錯,只要你可以瀏覽到東西我不能說你的假設是有道理的。此外,您在global.asax中用於初始化的模式也由others使用。

AsyncController需要異步方法是成對出現的,你的情況IndexAsync & IndexCompleted。這些代碼共同代表Index操作。當你說你可以導航到IndexCompleted,你的意思是你打開一個URL「..../IndexCompleted」?

此外,我不能從任何文檔確認,但我想AsyncController要求所有操作都是異步的。因此,您的NewMessage操作會造成問題,應轉換爲異步對。

0

我沒太需要有AsyncController我很容易地改變FilterResolvingActionInvoker是基於AsyncControllerActionInvoker而不是ControllerActionInvoker

但由於請求完成後的自動事務處理,還有其他問題。在AsyncController起始螺紋並且完成該請求可以是不同的,其拋出以下異常在TransactionManager類的Dispose方法線程:

TransactionScope一個必須被設置,它創建的相同的線程上。

這個異常在沒有任何日誌記錄的情況下被抑制,真的很難發現。在這種情況下,會話不會處理,隨後的會話將超時。
所以我做了ITransactionManager Dispose方法公開,現在在我的AsyncController,每當我需要一個查詢到數據庫中,我把它包在:

using (_services.TransactionManager) { 
    ..... 
} 

新的事務管理器:

public interface ITransactionManager : IDependency, IDisposable { 
    void Demand(); 
    void Cancel(); 
} 

public class TransactionManager : ITransactionManager { 
    private TransactionScope _scope; 
    private bool _cancelled; 

    public TransactionManager() { 
     Logger = NullLogger.Instance; 
    } 

    public ILogger Logger { get; set; } 

    public void Demand() { 
     if (_scope == null) { 
      Logger.Debug("Creating transaction on Demand"); 
      _scope = new TransactionScope(
       TransactionScopeOption.Required, 
       new TransactionOptions { 
        IsolationLevel = IsolationLevel.ReadCommitted 
       }); 
      _cancelled = false; 
     } 
    } 

    void ITransactionManager.Cancel() { 
     Logger.Debug("Transaction cancelled flag set"); 
     _cancelled = true; 
    } 

    void IDisposable.Dispose() { 
     if (_scope != null) { 
      if (!_cancelled) { 
       Logger.Debug("Marking transaction as complete"); 
       _scope.Complete(); 
      } 

      Logger.Debug("Final work for transaction being performed"); 
      try { 
       _scope.Dispose(); 
      } 
      catch { 
       // swallowing the exception 
      } 
      Logger.Debug("Transaction disposed"); 
     } 
     _scope = null; 
    } 
} 

請注意我對TransactionManager做了其他小改動。

0

我嘗試了AsyncControllerActionInvoker路由以及無濟於事。我會得到從烏節本身的間歇性錯誤有以下錯誤:

Orchard.Exceptions.DefaultExceptionPolicy - An unexpected exception was caught 
System.TimeoutException: The operation has timed out. 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() 
    at System.Web.Mvc.Async.ReflectedAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3f.<BeginInvokeAsynchronousActionMethod>b__3e(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() 
NHibernate.Util.ADOExceptionReporter - While preparing SELECT this_.Id as Id236_2_, this_.Number as Number236_2_,...<blah blah blah> 
NHibernate.Util.ADOExceptionReporter - The connection object can not be enlisted in transaction scope. 

所以我不認爲只是包裝自己的數據庫調用與事務對象會有所幫助。烏節的內臟也必須修改。

去投票,如果你想在果園支持AsyncControllers這個問題:

https://orchard.codeplex.com/workitem/18012