Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 服务存储库模式设计注意事项_Asp.net Mvc 3_Design Patterns_Repository Pattern - Fatal编程技术网

Asp.net mvc 3 服务存储库模式设计注意事项

Asp.net mvc 3 服务存储库模式设计注意事项,asp.net-mvc-3,design-patterns,repository-pattern,Asp.net Mvc 3,Design Patterns,Repository Pattern,下面的代码工作得很好,但是我有一些关于它的设计的问题 BlogEntry.cs public class BlogEntry : EntityBase { /// <summary> /// Gets or sets the blog entry comments. /// </summary> public virtual ICollection<BlogEntryComment> Bl

下面的代码工作得很好,但是我有一些关于它的设计的问题

BlogEntry.cs

    public class BlogEntry : EntityBase
    {
       /// <summary>
       /// Gets or sets the blog entry comments.
       /// </summary>
       public virtual ICollection<BlogEntryComment> BlogEntryComments { get; set; }
    }
BlogEntryService.cs

public class BlogEntryService : GenericEntityService<BlogEntry>, IBlogEntryService
{
    /// <summary>
    /// Initializes a new instance of the <see cref="BlogEntryService"/> class.
    /// </summary>
    /// <param name="unitOfWork">The <see cref="IUnitOfWork"/>.</param>
    public BlogEntryService(IUnitOfWork unitOfWork)
        : base(unitOfWork.BlogEntries, unitOfWork)
    {
    }
public abstract class GenericEntityService<T> : IGenericEntityService<T> where T : MVCBlog.Core.Entities.EntityBase
{
    /// <summary>
    /// Initializes a new instance of the <see cref="GenericEntityService&lt;T&gt;"/> class.
    /// </summary>
    /// <param name="repository">The <see cref="MVCBlog.Core.Repository.IRepository{T}"/>.</param>
    /// <param name="unitOfWork">The <see cref="IUnitOfWork"/>.</param>
    protected GenericEntityService(IRepository<T> repository, IUnitOfWork unitOfWork)
    {
        this.Repository = repository;
        this.UnitOfWork = unitOfWork;
    }
公共类BlogEntryService:GenericeEntityService、IBlogEntryService
{
/// 
///初始化类的新实例。
/// 
///这个。
公共博客服务(IUnitOfWork unitOfWork)
:base(unitOfWork.BlogEntries,unitOfWork)
{
}
GenericEntityService.cs

public class BlogEntryService : GenericEntityService<BlogEntry>, IBlogEntryService
{
    /// <summary>
    /// Initializes a new instance of the <see cref="BlogEntryService"/> class.
    /// </summary>
    /// <param name="unitOfWork">The <see cref="IUnitOfWork"/>.</param>
    public BlogEntryService(IUnitOfWork unitOfWork)
        : base(unitOfWork.BlogEntries, unitOfWork)
    {
    }
public abstract class GenericEntityService<T> : IGenericEntityService<T> where T : MVCBlog.Core.Entities.EntityBase
{
    /// <summary>
    /// Initializes a new instance of the <see cref="GenericEntityService&lt;T&gt;"/> class.
    /// </summary>
    /// <param name="repository">The <see cref="MVCBlog.Core.Repository.IRepository{T}"/>.</param>
    /// <param name="unitOfWork">The <see cref="IUnitOfWork"/>.</param>
    protected GenericEntityService(IRepository<T> repository, IUnitOfWork unitOfWork)
    {
        this.Repository = repository;
        this.UnitOfWork = unitOfWork;
    }
公共抽象类GenericeEntityService:IGenericEntityService其中T:MVCBlog.Core.Entities.EntityBase
{
/// 
///初始化类的新实例。
/// 
///这个。
///这个。
受保护的GenericeEntityService(IRepository存储库、IUnitOfWork unitOfWork)
{
this.Repository=Repository;
this.UnitOfWork=UnitOfWork;
}
}

  • 应该使用BlogEntryService.AddComment(..)方法或使用它自己的blogentryscommentservice.Add(..)方法将注释添加到数据库中,与当前实现一样
  • 我正在验证控制器中的用户和BlogEntry,此验证应该是服务层的一部分?例如[service].AddComment(Guid blogEntryId、字符串用户名、字符串注释)
  • 还有其他改进设计或代码的想法吗
  • 根据SRP(单响应主体),它应该是BlogEntryCommentService.Add(..)
  • 我想,这不是servicelayer验证
  • 根据SRP(单响应主体),它应该是BlogEntryCommentService.Add(..)
  • 我想,这不是servicelayer验证

  • 您的存储库在哪里?使用我的服务/存储库/UnitofWork更新了代码?您的存储库在哪里?使用我的服务/存储库/UnitofWork更新了代码