repository-pattern

DDD: Entity identity before being persisted

百般思念 提交于 2019-11-28 23:44:56
问题 In Domain Driven Design, one of the defining characteristic of an Entity is that it has an identity. Problem: I am not able to provide a unique identity to Entities on instance creation. This identity is only provided by the repository once the entity is persisted (this value is provided from the underlying database). I cannot begin to use Guid values at this point. The existing data is stored with int primary key values and I cannot generate a unique int on instantiation. My solution: Each

How to write Repository method for .ThenInclude in EF Core 2

可紊 提交于 2019-11-28 23:28:39
I'm trying to write a repository method for Entity Framework Core 2.0 that can handle returning child collections of properties using .ThenInclude, but I'm having trouble with the second expression. Here is a working method for .Include, which will return child properties (you supply a list of lambdas) of your entity. public T GetSingle(Expression<Func<T, bool>> predicate, params Expression<Func<T, object>>[] includeProperties) { IQueryable<T> query = _context.Set<T>(); foreach (var includeProperty in includeProperties) { query = query.Include(includeProperty); } return query.Where(predicate)

Some issues about Rob Conery's repository pattern

寵の児 提交于 2019-11-28 23:16:18
问题 Please read my update at the end of question after reading the answers: I'm trying to apply repository pattern as Rob Conery's described on his blog under " MVC Storefront ". But I want to ask about some issues that I had before I apply this design pattern. Rob made his own "Model" and used some ORM "LINQ to SQL or Entity Framework (EF)" to map his database to Entities. Then he used custom Repositories which gives IQueryable<myModel> and in these repositories he made sort of Mapping or

DDD repository and factory

僤鯓⒐⒋嵵緔 提交于 2019-11-28 23:06:17
问题 In my application a few layers. In this topic will focus on Domain and Infrastructure layers. I have repository interface ClientRepositoryInterface in Domain layer. And I have implementation of this interface ClientRepositoryImpl in Infrastructure layer. But to reconstitute the object in the middle of the cycle of its existence I need factory(ReconstitutionClientFactory). Call the factory will be in the repository. The book by Eric Evans is described as a normal practice. But where this

Onion Architecture, Unit of Work and a generic Repository pattern

六月ゝ 毕业季﹏ 提交于 2019-11-28 17:17:43
This is the first time I am implementing a more domain-driven design approach. I have decided to try the Onion Architecture as it focuses on the domain rather than on infrastructure/platforms/etc. In order to abstract away from Entity Framework, I have created a generic repository with a Unit of Work implementation. The IRepository<T> and IUnitOfWork interfaces: public interface IRepository<T> { void Add(T item); void Remove(T item); IQueryable<T> Query(); } public interface IUnitOfWork : IDisposable { void SaveChanges(); } Entity Framework implementations of IRepository<T> and IUnitOfWork :

Is a static repository a right way to use NHibernate?

為{幸葍}努か 提交于 2019-11-28 17:14:32
问题 I spent the rest of the evening reading StackOverflow questions and also some blog entries and links about the subject. All of them turned out to be very helpful, but I still feel that they don't really answer my question. So, I'm developing a simple web application. I'd like to create a reusable data access layer which I can later reuse in other solutions. 99% of these will be web applications. This seems to be a good excuse for me to learn NHibernate and some of the patterns around it. My

Specification Pattern in Domain Driven Design

坚强是说给别人听的谎言 提交于 2019-11-28 17:05:15
I've been struggling around an DDD related issue with Specifications and I've read much into DDD and specifications and repositories. However, there is an issue if trying to combine all 3 of these without breaking the domain driven design. It boils down to how to apply filters with performance in mind. First a few obvious facts: Repositories to got DataAccess/Infrastructure Layer Domain Models represent Business Logic and go to the Domain layer Data Access Models represent Persistence layer and go to the Persistance/Infrastructure/DataAccess layer Business Logic goes to Domain Layer

How do read-only database views fit into the repository pattern?

北城以北 提交于 2019-11-28 16:50:51
问题 Example: Your database has a SQL view named "CustomerOrdersOnHold". This view returns a filtered mix of specific customer and order data fields. You need to fetch data from this view in your application. How does access to such a view fit into the repository pattern? Would you create a "CustomerOrdersOnHoldRepository"? Is a read-only view such as this considered an aggregate root? 回答1: I would prefer separating the read repository, preferably even change its name to Finder or Reader, the

Repository pattern with Entity framework

我是研究僧i 提交于 2019-11-28 16:25:26
Repository pattern is used to abstract from particular database and object-relation-mapping technology(like EF) used. So I can easily replace (for example) my Entity framework mappings with Linq to SQL in the future if I decide to do so. But when I use EF I have my entity classes from the model - that is they are generated from that visual diagram. If I use this generated entity classes in my repository and then decide to replace EF by something else then I will delete that visual entity diagram and that means also to delete classes right ? The point I'm addressing is that my repository will

Entity Framework using Repository Pattern, Unit of Work and Unity

安稳与你 提交于 2019-11-28 16:22:23
问题 Using a combination provided from this example and this implementation I am trying to create a solution that decouples the UnitOfWork class from the individual repositories, as they violate the Open-Closed Principle, since every time you added a new repository you would have to modify the UnitOfWork class. I am using Unity as the IoC container to wire up dependencies. The problem I have is that in automatically wiring up the UnitOfWork , IDbContext and the repositories ( IEmployeeRepository