repository-pattern

Should write complex query in Repository or Service layer?

余生长醉 提交于 2019-11-30 04:02:14
问题 I are planning migrate our data access layer to using repository pattern and unit of work. I do know repository will help me to change persistence store (database, collection...etc) and technology such as EF to MongoDB easily. So I noticed some key points of implementation of a repository such as: Return IEnumerable instead of IQueryable Repository should take responsibilities for CRUD operations only Return type of repository method should be model (entity) Only implement repository for

DDD repository and factory

人走茶凉 提交于 2019-11-30 02:14:24
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 factory(ReconstitutionClientFactory) should be located? In Domain or in Infrastructure layer? I think in

DDD: Entity identity before being persisted

孤者浪人 提交于 2019-11-30 02:14:20
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 Entity has an identity value The identity is only set to a real identity once persisted (provided by the

Repository Pattern - Caching

折月煮酒 提交于 2019-11-30 01:29:48
I'm not sure where I should implement the caching in my repository pattern. Should I implement it in the service-logic or in the repository? GUI -> BusinessLogic (Services) -> DataAccess (Repositories) I would handle it in the repository/data access layer. The reasoning is because it isn't up to the business layer on where to get the data from, that is the job of the repository. The repository will then decide where to get the data from, the cache (if it's not too old) or from the live data source based on the circumstances of the data access logic. It's a data access concern more than a

EF and repository pattern - ending up with multiple DbContexts in one controller - any issues (performance, data integrity)?

天大地大妈咪最大 提交于 2019-11-30 00:56:11
Most of my knowledge of ASP.NET MVC 3 comes from reading through the book Pro ASP.NET MVC 3 Framework by Adam Freeman and Steven Senderson. For my test application I have tried to stick to their examples very closely. I am using the repository pattern plus Ninject and Moq which means that unit testing work quite well (i.e. without needing to pull data from the database). In the book repositories are used like this: public class EFDbTestChildRepository { private EFDbContext context = new EFDbContext(); public IQueryable<TestChild> TestChildren { get { return context.TestChildren; } } public

What exactly is the difference between a data mapper and a repository?

亡梦爱人 提交于 2019-11-30 00:26:20
Well I've been trying to find out the difference between data mapper and repository, but up to now I still have not. It seems to me that the expert programmer said "Repository is another layer of abstraction over the mapping layer where query construction code is concentrated". It seems understandable but is still somewhat very abstract. I read this article on stackoverflow before, and it just made me even more confused: How is the Data Mapper pattern different from the Repository Pattern? I guess what I need are simple explanations and concrete/practical examples on how the two patterns

It's not possible to lock a mongodb document. What if I need to?

女生的网名这么多〃 提交于 2019-11-29 23:58:53
I know that I can't lock a single mongodb document, in fact there is no way to lock a collection either. However, I've got this scenario, where I think I need some way to prevent more than one thread (or process, it's not important) from modifying a document. Here's my scenario. I have a collection that contains object of type A. I have some code that retrieve a document of type A, add an element in an array that is a property of the document ( a.arr.add(new Thing() ) and then save back the document to mongodb. This code is parallel, multiple threads in my applications can do theses operations

Repository / IQueryable / Query Object

∥☆過路亽.° 提交于 2019-11-29 22:26:19
I am building a repository and I've seen in many places 2 reasons not to expose IQueryable outside the repository. 1) The first is because different LINQ providers could behave differently, and this difference should be contained within the repository. 2) The second is to prevent service level developers from modifying the database query such that it accidentally causes performance issues. I guess issue 2 can only be prevented by keeping all query logic within the repository and not allowing any form of external query building? But that does seem a bit impractical to me. Issue 1 would seem to

Need a simple example of using nhibernate + unit of work + repository pattern + service layer + ninject

送分小仙女□ 提交于 2019-11-29 22:24:24
I am using nhibernate + fluent nhibernate asp.net mvc 3 ninject Currently I am using nhibernate, ninject with the repository pattern and service layers. So I have this ninject public class NhibernateSessionFactory { public ISessionFactory GetSessionFactory() { ISessionFactory fluentConfiguration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString"))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.TableAMap>().Conventions.Add(ForeignKey.EndsWith("Id"))) .ExposeConfiguration(cfg => cfg

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

假如想象 提交于 2019-11-29 20:44:09
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? Mohamed Abed I would prefer separating the read repository, preferably even change its name to Finder or Reader, the repository is meant for Domain usage not for querying read-only data, you can refer to this article