简单学习下Oxite的项目结构2

前一篇:简单学习下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);
    //}
}

剩下的这三个项目没什么好说的了:

image

View部分简单看了下,总体来说感觉比较乱吧。Orz...

后记:忽然觉得本文基本是废话。因为从整体上来看,本人没发现这个项目有什么突出的地方、值得深入去分析的地方,完全没有看BlogEngine时候的那种酣畅淋漓的快感。也许是本人愚钝,还望高人指点。没有仔细的深入到代码的学习,这个就不做评论了。

Enjoy!Post by Q.Lee.lulu

原文地址:https://www.cnblogs.com/QLeelulu/p/learn_Oxite_2.html