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;//生成一个评论对象

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

 

转载于:https://www.cnblogs.com/xchsp/archive/2011/12/16/2289848.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值