Asp.net mvc 3 服务存储库模式设计注意事项
下面的代码工作得很好,但是我有一些关于它的设计的问题 BlogEntry.csAsp.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
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<T>"/> 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<T>"/> 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、字符串用户名、字符串注释)
- 还有其他改进设计或代码的想法吗
您的存储库在哪里?使用我的服务/存储库/UnitofWork更新了代码?您的存储库在哪里?使用我的服务/存储库/UnitofWork更新了代码