技术开发 频道

Visual Studio 2008+NClay小试牛刀

    视图

   
由于VS2008对默认属性的支持,这样大在减少了NClay下的视图代码;在VS2005里不得不对编辑器生成的接口代码进行调整。而VS2008下直接编辑生成接口代码就可以,省了不少修改的工作。
[NClay.MVC.Action(ActionType = NClay.MVC.ActionType.All, Tag = "~/Default.aspx", Services = new Type[] { typeof(Logic.Post.IPostView) })] public class Default :BaseView ,Logic.Post.IPostView {  #region IPostView 成员  public string CategoryID  { get; set; }  public System.Collections.Generic.IList<SmallBlog.Entities.PostView> Posts  { get; set; }  #endregion  #region IDataPageProperty 成员  [NClay.MVC.Bind(typeof(NClay.DataPage))]  public NClay.IDataPage DataPage  { get; set; }  #endregion }
    AOP扩展

   
很多时候面对多个视图处理同样的逻辑,这时候可以借助于框架的AOP功能完成。以下是统一处理页面左则的功能
[NClay.MVC.ViewAspect(NClay.MVC.AspectLevel.High)] public class AspectBaseView:NClay.MVC.IAspect {  #region IAspect 成员  public void Aspect(object source, NClay.MVC.AspectHandler e)  {   if (source is BaseView)   {    BaseView bv = (BaseView)source;    NClay.MVC.Container.Execute<Logic.SysUser.IBlogConfig>(bv, true);    NClay.MVC.Container.Execute<Logic.Category.IStatCategories>(bv, true);    NClay.MVC.Container.Execute<Logic.Post.IHotPost>(bv, true);   }   e.Execute(source);  }  #endregion }
    为了避加载重复的数据,可以通过AOP来实现逻辑数据的缓存处理。
[NClay.MVC.LogicAspect(typeof(Logic.SysUser.IBlogConfig),   typeof(Logic.SysUser.IEditUserInfo))] public class BlogConfigCache : NClay.MVC.IAspect {  #region IAspect 成员  public void Aspect(object source, NClay.MVC.AspectHandler e)  {   if (source is Logic.SysUser.IBlogConfig)   {    Logic.SysUser.IBlogConfig config = (Logic.SysUser.IBlogConfig)source;    config.OwnerConfig = CacheUnit.GetBlogConfig();    if (config.OwnerConfig == null)    {     e.Execute(source);     CacheUnit.SetBlogConfig(config.OwnerConfig);    }   }   if (source is Logic.SysUser.IEditUserInfo)   {    e.Execute(source);    CacheUnit.ClearBlogConfig();   }  }  #endregion }

    程序运行效果图

0
相关文章