repository-pattern

Is it ok for entities to access repositories?

混江龙づ霸主 提交于 2019-11-26 15:26:15
I've just started working with DDD, so maybe this is a silly question... Is it ok for an entity to access a repository (via some IRepository interface) to get a value at runtime? For example, I want to enforce a "default" selection for a property: class Person { private Company _employer; public Company Employer { get { return _employer; } set { if(value != null) { _employer = value; } else { _employer = employerRepository.GetDefaultEmployer(); } } } ... } My question is whehter doing something like this is a horrible violation of DDD principles. And if it isn't, my next question would be what

Repository Pattern in Entity framework 4 when should we dispose?

耗尽温柔 提交于 2019-11-26 15:05:24
问题 New to EF and I have noticed that using a repository pattern can really simplify things and will allow me to do some mocking too.So far so good. My Question A typical usage of the objectContext is to destroy as soon as possible see below using (var context = new SchoolEntities()) { context.AddToDepartments(department); context.SaveChanges(); } Using the Repository pattern I have noticed that nobody actually uses the "Using Pattern" eg using (var repository= new Repository<Student>(new

Using Simple Injector with Unit Of Work & Repository Pattern in Windows Form

心不动则不痛 提交于 2019-11-26 13:19:55
问题 I'm trying to implement IoC in my windows form application. My choice fell on Simple Injector, because it's fast and lightweight. I also implement unit of work and repository pattern in my apps. Here is the structure: DbContext : public class MemberContext : DbContext { public MemberContext() : base("Name=MemberContext") { } public DbSet<Member> Members { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder

Is it possible to remove child from collection and resolve issues on SaveChanges?

主宰稳场 提交于 2019-11-26 12:55:51
问题 We are using Entity Framework Code First with Foreign Key relationships. We investigating on ways on handling removing objects from an entities ICollection in our application. When we have an entity with child relationships we can add objects directly to their ICollection using Add method. Now when you use remove you get the error System.InvalidOperationException occurred Message=The operation failed: The relationship could not be changed because one or more of the foreign-key properties is

Entity Framework 6 Code First - Is Repository Implementation a Good One?

我的未来我决定 提交于 2019-11-26 11:46:17
问题 I am about to implement an Entity Framework 6 design with a repository and unit of work. There are so many articles around and I\'m not sure what the best advice is: For example I realy like the pattern implemented here: for the reasons suggested in the article here However, Tom Dykstra (Senior Programming Writer on Microsoft\'s Web Platform & Tools Content Team) suggests it should be done in another article: here I subscribe to Pluralsight , and it is implemented in a slightly different way

Entity Framework .Where nested in .Include

折月煮酒 提交于 2019-11-26 11:38:05
问题 I\'m attempting to perform a db lookup using EF5 code-first. The basic structure and table relationships are as follows; public partial class Member { public int RecordID {get; set;} public string Name {get; set;} ...etc. public virtual ICollection<MemberLink> MasterLinks {get; set;} public virtual ICollection<MemberLink> SlaveLinks {get; set;} public virtual ICollection<Message> ReceivedMessages {get; set;} public virtual ICollection<Message> SentMessages {get; set;} } public partial class

EF Including Other Entities (Generic Repository pattern)

我只是一个虾纸丫 提交于 2019-11-26 11:30:39
I am using the Generic Repository pattern on top of Entity Framework Code First. Everything was working fine until I needed to include more entities in a query. I got to include one entity successfully, but now I can't figure out how to include multiple entities. Check out what I've got so far: public IQueryable<TEntity> GetQuery<TEntity>() where TEntity : class { var entityName = GetEntityName<TEntity>(); return _objectContext.CreateQuery<TEntity>(entityName); } public IList<TEntity> GetQueryWithInclude<TEntity>(string toInclude) where TEntity : class { var entityName = GetEntityName<TEntity>

How are Spring Data repositories actually implemented?

只愿长相守 提交于 2019-11-26 10:09:22
I have been working with Spring Data JPA repository in my project for some time and I know the below points: In the repository interfaces, we can add the methods like findByCustomerNameAndPhone() (assuming customerName and phone are fields in the domain object). Then, Spring provides the implementation by implementing the above repository interface methods at runtime (during the application run). I am interested on how this has been coded and I have looked at the Spring JPA source code & APIs, but I could not find answers to the questions below: How is the repository implementation class

Proper Repository Pattern Design in PHP?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 10:04:24
问题 Preface: I\'m attempting to use the repository pattern in an MVC architecture with relational databases. I\'ve recently started learning TDD in PHP, and I\'m realizing that my database is coupled much too closely with the rest of my application. I\'ve read about repositories and using an IoC container to \"inject\" it into my controllers. Very cool stuff. But now have some practical questions about repository design. Consider the follow example. <?php class DbUserRepository implements

DDD - the rule that Entities can&#39;t access Repositories directly

人盡茶涼 提交于 2019-11-26 09:05:22
问题 In Domain Driven Design, there seems to be lots of agreement that Entities should not access Repositories directly. Did this come from Eric Evans Domain Driven Design book, or did it come from elsewhere? Where are there some good explanations for the reasoning behind it? edit: To clarify: I\'m not talking about the classic OO practice of separating data access off into a separate layer from the business logic - I\'m talking about the specific arrangement whereby in DDD, Entities are not