小编Sun*_*lUK的帖子

通用存储库模式 - DDD 实现

我目前正在尝试实现一个简单的博客应用程序以用于学习目的。它在 DDD 架构内。
我关心的是如何实现通用存储库模式。
你们能否就我是否正确实施存储库提出您的想法。
这是我第一次使用通用存储库,看起来我根本没有使用它。
下面显示了我的用户存储库的实现。
非常感谢

public interface IRepository<TEntity> where TEntity : class
{
    TEntity GetById(int id);
    IEnumerable<TEntity> GetAll();
    IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate);
    void Add(TEntity entity);
    void Update(TEntity entity);
    void Remove(TEntity entity);
}

//Implementation of Generic Repo

using BA.Infrastructure.Data.Context;
using BA.Infrastructure.Data.Interfaces.Helpers;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;

namespace BA.Infrastructure.Data.Repositories.Helpers
{
    public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
    {
        protected readonly BlogDbContext _context;

        public Repository(BlogDbContext context)
        {
            _context = context;
        }

        public TEntity …
Run Code Online (Sandbox Code Playgroud)

c# domain-driven-design unit-of-work repository-pattern

2
推荐指数
1
解决办法
2362
查看次数