zoukankan      html  css  js  c++  java
  • wojilu评论功能代码分析简记

    最近,简单看了一下wojilu评论功能的实现,作者介绍文章(http://www.wojilu.com/Common/Page/52)

    FileComment : ObjectBase<FileComment>, IComment

      FileComment实现 IComment接口, IComment 接口定义了一个评论对象应该表现的行为。

    另外,FileCommentController : CommentController<FileComment>。

    public class CommentController<T> : ControllerBase where T : ObjectBase<T>, IComment

    {
    public ICommentService<T> commentService { get; set; }

     CommentController 组合使用 CommentService<T>对象,管理评论。

     看一个 CommentController中 的方法Create,创建评论

    [HttpPost, DbTransaction]
     public virtual void Create( int postId ) {
     ......
     IComment comment = Validate( postId );//验证并获取一个评论对象
    ......
     Result result = commentService.Insert( comment, lnkTarget );//保存评论对象到数据库。
    ......

    public IComment Validate( int postId ) {

     IComment comment = Entity.New( typeof( T ).FullName ) as IComment;//生成一个评论对象
     ......
    comment.RootId = postId;
    comment.ParentId = ctx.PostInt( "ParentId" );
    comment.AppId = ctx.app.Id;
    comment.Author = userName;
    comment.Content = content;
    comment.Ip = ctx.Ip;
    comment.Created = DateTime.Now;

    if (ctx.viewer.IsLogin) {
    comment.Member = (User)ctx.viewer.obj;
    }
    return comment;

     学习这段代码收获很多,加深了对接口用法的理解,了解了泛型约束的概念。

     IComment comment = Entity.New( typeof( T ).FullName ) as IComment;//生成一个评论对象

    以上,有时间在学习体会一下。 

  • 相关阅读:
    Windows Server 2012配置开机启动项
    Windows Server 2019 SSH Server
    NOIP2017 senior A 模拟赛 7.7 T1 棋盘
    Noip 2015 senior 复赛 Day2 子串
    Noip 2015 senior复赛 题解
    Noip 2014 senior Day2 解方程(equation)
    Noip 2014 senior Day2 寻找道路(road)
    Noip 2014 senior Day2 无线网络发射器选址(wireless)
    Noip2014senior复赛 飞扬的小鸟
    Noip 2014 senior 复赛 联合权值(link)
  • 原文地址:https://www.cnblogs.com/xchsp/p/2289848.html
Copyright © 2011-2022 走看看