2010-01-06 68 views
2

我目前通過靜態調用如是否可以在流暢配置中使用不同的CurrentSessionContexts?

SessionConfiguration.GetSessionConfiguration(); 

建立我的會話配置的方法上面返回一個配置的ISessionFactory:

public static ISessionFactory GetSessionConfiguration() 
{ 
    return Fluently.Configure() 
     .Database(MsSqlConfiguration 
      .MsSql2005 
      .ConnectionString(/*...*/) 
      .ShowSql() 
      .CurrentSessionContext<WebSessionContext>()) 
     .Mappings(/*etc*/) 
     .BuildSessionFactory(); 
} 

我尋找到的部分是「CurrentSessionContext < >」。我希望能夠根據調用它的應用程序來設置它。大部分時間通過網絡應用程序訪問這個庫,所以上述工作正常。但是,最近我需要在控制檯應用程序中使用此層,其中CallSessionContext似乎更合適。

是否可以傳遞ICurrentSessionContext以便使用?

我試圖沿着線的東西:

public static ISessionFactory GetSessionConfiguration<ICurrentSessionContext> 

public static ISessionFactory GetSessionConfiguration<TSessionContext> 

,但還沒有任何運氣,只是還沒有。

任何援助非常感謝!

回答

2

這是可能的使用「where約束」。

即:

ISessionFactory GetSessionConfiguration<T> where T : ICurrentSessionContext 

調用時,這可以讓你做到以下幾點:

SessionConfiguration.GetSessionConfiguration<CallSessionContext>(); 
相關問題