repository-pattern

GenericRepository TEntity change attribute value

倾然丶 夕夏残阳落幕 提交于 2019-12-08 13:20:57
问题 I am using EF 5.0 and the model first approach. I have build a GenericRepository that has the basic get, insert, delete etc statements. Like: public virtual void Insert(TEntity entity) { dbSet.Add(entity); } My EF entities all have the attributes Modified and ModifiedBy. Now I want to change this values everytime I save an entity. Is it possible to modify this two attributes (set the value) without writing an specific implementation all the time? Thank you 回答1: I see two options for you to do

Application of repository pattern in android [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 12:35:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . i m working on an android application with repository pattern but i I could not find a complete series of practical implementations of repository pattern in android. any recommended tutorial? 回答1: I run into the same question and found a good article that compares different approaches for Repository in Android:

How to correctly dispose objects registered with Autofac

╄→尐↘猪︶ㄣ 提交于 2019-12-08 11:58:41
问题 I've implemented Unit of Work/Repository pattern, as described here, but I'm also using autofac and constructor injection, so I registered UnitOfWork and DbContext (PsyProfContext) class like this: builder.Register(context => new PsyProfContext()).InstancePerHttpRequest(); builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerHttpRequest(); And everything works great! Except for one thing: I'm also using enterprise library logging block, and I have implemented CustomTraceListener

IRepository Aggregates and Lazy Loading

99封情书 提交于 2019-12-08 11:53:00
问题 I've been trawling stackoverflow and the internet in general all day about the IRepository pattern trying to better understand it before I try and use it in anger. From what I've read (and please do correct me if I'm mistaken) a repoistory encapsulates access to its aggregate root and child objects exposing a common interface that can then be injected or mocked. So in the instance where you have your aggregate root object: class Employee { string FirstName; string LastName; IEnumerable

How to use one database context for all instances that make use of a repository?

孤街醉人 提交于 2019-12-08 10:44:30
问题 I have made some architectural MVC-mistake since I did not know of the An entity object cannot be referenced by multiple instances of IEntityChangeTracker. error. My setup is as follows: I have a repository for accessing the database which creates an instance of dbcontext , I have controllers that instantiate managers they need, the managers all instantiate their own repository . Here is the problem, when a controllers uses more than one manager to collect data and then try to create an

Generic Class for CRUD - Dependency Injection in C# using Repository and Unit Of Work Pattern

十年热恋 提交于 2019-12-08 10:42:22
问题 Trying to create a Generic Repository Class for implementing basic CRUD operations in C# using dependency injection, unit of work and repository patterns. I am very new to these concepts. Following is my code. public interface IUnitOfWork { IApplicationUserRepository Users { get; } ICompanyRepository Companies { get; } void Complete(); } public class UnitOfWork : IUnitOfWork { private readonly ApplicationDbContext _context; public IApplicationUserRepository Users { get; private set; } public

Can an Entity access a Repository?

半城伤御伤魂 提交于 2019-12-08 09:38:28
问题 Say I've got two simple entities: User and Review. How bad is it if User calls the Review repository? What is the "clean" way for the User to get its Reviews? class User { public function getReviews() { return reviewRepository.findByUser(this); } } I did have a look at this question, but although they say this is a bad practice, I didn't find an answer there. 回答1: The clean way in DDD is to have the UserRepository fill the reviews of the User when asking for a User. class UserRepository {

Aggregate Roots DDD/UoW/Repo/Service

蹲街弑〆低调 提交于 2019-12-08 09:14:34
问题 I have some questions about the Aggregate Objects for Repositories. I'm making a Rest Service with DDD/UoW/Repo and Service pattern. Our new cloud web-apps shall use this service. In order to do this, we also have to sync data from the old databases, which are still in production. We created a "SyncService" which read and writes to/from the cloud and down to earth. In my Rest/DDD-design. And I don't want the business logic to run on these, so in the original test project I have a repository

Repository pattern with EF6 + DatabaseFirst

 ̄綄美尐妖づ 提交于 2019-12-08 08:36:31
问题 Current System: I am working on a project which is multi layered as shown below (in order of flow) and I am learning and trying to implement Repo Pattern with UOW on EF Database first. Service (Web API) Business (C# Class Library) Repository (Repo Pattern + UOW) ViewModels (Used by my Service for sent to my UI layer) Data (Entities) Database (SQL Server) Repository: Generic Repository: public interface IRepository<TEntity> where TEntity : class { void Create(TEntity entity); IQueryable

Class derived from Generic Repository

牧云@^-^@ 提交于 2019-12-08 08:26:51
问题 I have a Generic Repository class, see below, which is used to perform common Data Access functions, ie, Add, GetByID etc. public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class { internal GolfEntities context; internal DbSet<TEntity> dbSet; public GenericRepository(GolfEntities context) { this.context = context; this.dbSet = context.Set<TEntity>(); } public TEntity GetByID(object id) { return dbSet.Find(id); } I would like to create another Repository