我正在尝试使用一个简单的示例(例如用户有很多帖子)来推出具有实体框架和存储库模式的策略User
模式Post
。
从这里的答案中,我有以下域:
public interface IUser {
public Guid UserId { get; set; }
public string UserName { get; set; }
public IEnumerable<Post> Posts { get; set; }
}
添加接口以支持您将在其中使用用户的角色。
public interface IAddPostsToUser : IUser {
public void AddPost(Post post);
}
现在我的存储库如下所示:
public interface IUserRepository {
User Get<TRole>(Guid userId) where TRole : IUser;
}
策略(我被困的地方)。我该怎么处理这段代码?我可以举个例子来说明如何实现这个,我在哪里放这个?
public interface IFetchingStrategy<TRole> {
TRole Fetch(Guid id, IRepository<TRole> role)
}
我的基本问题是这个问题中的问题。我希望能够使用策略模式获得没有帖子的用户和有帖子的用户。