前一篇:簡單學習下Oxite的項目結構-1
Oxite.BackgroundServices項目,前面已經說過,略。
Oxite.Database項目:
一個資料庫專案,方便資料庫結構描述、資料的對比、更新與部署。這個就沒什麼好說的了,誰用誰知道。
Oxite.LinqToSqlDataProvider項目,前面已提過,略。
Oxite.LiveSearchProvider項目,對M$的LiveSearch API有興趣的可以看下,在這裡略過。
Oxite.Mvc項目:
Oxite.Mvc這個項目就是將MVC中的C層抽離出來,同時這裡還包含一點核心的V層的東西。
Oxite.Mvc項目中的Controllers目錄,裡面的當然就是放的Controller拉。很自然的,這裡有一個oXite的BaseController,裡面定義一些公用的東東,例如AppSetting、常用的Repository介面,一些公用的方法,例如NotFound()、Localize(),同時還重寫兩個View方法,返回OxiteViewResult類型。
Oxite.Mvc項目中的Views目錄,定義了主版頁面、視圖頁、使用者控制項的基底類型,裡面也是定義了一些常用的屬性和方法,前面說了在BaseController已經定義了一些常用的屬性和方法,這裡注意一下在view的基類中是怎樣定義這些常用屬性和方法的,我們直接看一下BaseViewPage中的一些代碼吧:
public AppSettingsHelper AppSettings{ get { if (ViewContext.Controller is BaseController) { return ((BaseController)ViewContext.Controller).AppSettings; } return null; }}
public string GetAbsolutePath(string relativePath){ if (ViewContext.Controller is BaseController) { return ((BaseController)ViewContext.Controller).GetAbsolutePath(relativePath); } return null;}
從代碼中可以看到,這裡是直接返回BaseController中的結果的。同時在這些view的基類中還定義了例如註冊JS、CSS等和view有關的方法。
Oxite.Mvc項目根目錄下的類基本就是一些ViewResult的實現,還有一些Extensions類的實現以方便代碼的書寫,還有幾個ActionFilterAttribute的實現。
在這裡看一下其中的兩個類,先來看一下OxiteViewEngine類,這個就是IViewEngine的實現,以支援對Skins的支援:
public OxiteViewEngine(string skin){ defaultSkin = skin; MasterLocationFormats = new[] { "~/Skins/{2}/Views/{1}/{0}.master", "~/Skins/{2}/Views/Shared/{0}.master", "~/Views/{1}/{0}.master", "~/Views/Shared/{0}.master" }; ViewLocationFormats = new[] { "~/Skins/{2}/Views/{1}/{0}.aspx", "~/Skins/{2}/Views/{1}/{0}.ascx", "~/Skins/{2}/Views/Shared/{0}.aspx", "~/Skins/{2}/Views/Shared/{0}.ascx", "~/Views/{1}/{0}.aspx", "~/Views/{1}/{0}.ascx", "~/Views/Shared/{0}.aspx", "~/Views/Shared/{0}.ascx", }; PartialViewLocationFormats = ViewLocationFormats;}
建構函式需要一個skin參數,以指定使用的Skin。從上面的路徑可以看出搜尋View的時候是先從Skins目錄搜尋,搜不到再到Views目錄中搜。
下面再看一下OxiteApplication類,這個類是繼承自HttpApplication類的,就是將我們平時在Global.asax.cs中做的工作放到這裡來做:
protected virtual void OnStart(){ RegisterRoutes(); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new OxiteViewEngine(Config.Site.ThemeDefault)); backgroundServiceExecutors = BackgroundServicesExecutor.Start(Config);}protected virtual void OnEnd(){ BackgroundServicesExecutor.End(backgroundServiceExecutors);}
這裡主要就是註冊Routes規則、註冊ViewEngine、開始BackgroundServices的執行。
然後在直接繼承自這個類:
public class MvcApplication : Oxite.Mvc.OxiteApplication{ // Note: Uncomment and add/edit/remove routes below //public override void RegisterRoutes(RouteCollection routes, string[] areas) //{ // base.RegisterRoutes(routes, areas); //}}
剩下的這三個項目沒什麼好說的了:
View部分簡單看了下,總體來說感覺比較亂吧。Orz...
後記:忽然覺得本文基本是廢話。因為從整體上來看,本人沒發現這個項目有什麼突出的地方、值得深入去分析的地方,完全沒有看BlogEngine時候的那種酣暢淋漓的快感。也許是本人愚鈍,還望高人指點。沒有仔細的深入到代碼的學習,這個就不做評論了。
Enjoy!Post by Q.Lee.lulu