repository-pattern

Using the repository pattern to support multiple providers

房东的猫 提交于 2019-11-28 05:06:17
Well, not sure if that's exactly the right title, but basically I have been having a lot of problems using repositories in MVC applications in such a way that you can substitute one set of repositories, implementing a different data storage technology, for another. For example, suppose I want to use Entity Framework for my application. However, I also want to have a set of test data implemented in hard-coded Lists. I would like to have a set of interfaces (IUserRepository, IProductRepository, etc. -- let's not talk about a more generic IRepository<T> for now) that both approaches can

How to retrieve Domain Object from Repositories

余生颓废 提交于 2019-11-28 04:28:10
问题 I have a little problem understanding repository-domain object relation. Here is some information I know about domain design(they may also be wrong or not accurate). And with these in mind, I can't find a way to obtain a domain object from the repository. In DDD the domain should know and contain only whats needed for the business and everything else must be cleared out of the domain. That's fine. And also abstracting data access from any business is a good practice too. The application doesn

Best Repository Pattern for ASP.NET MVC

送分小仙女□ 提交于 2019-11-28 02:35:54
I recently learned ASP.NET MVC (I love it). I'm working with a company that uses dependency injection to load a Repository instance in each request, and I'm familiar with using that repository. But now I'm writing a couple of MVC applications of my own. I don't fully understand the hows and whys of the repository my company uses, and I'm trying to decide the best approach to implement data access. I am using C# and Entity Framework (with all the latest versions). I see three general approaches for handling data access. Regular DB context within a using statement each time I access data. This

Implementing Repository pattern and doing Tests

馋奶兔 提交于 2019-11-28 02:02:15
问题 I have read almost all articles about Repository pattern and different implementations of it. Many of them judged bad practices (ex: using IQueryable<T> instead of IList<T> ) etc. that why i'm still stuck and couldn't end-up to the right one. So: Do I need Repository pattern to apply IoC in my MVVM applications ? If yes, What is the efficient IRepository implementation to EF Entities which is a good practice and better testable ? How can I test my Repositories and UnitofWork behavior ? Unit

Entity Framework Repository Pattern why not return Iqueryable?

不问归期 提交于 2019-11-27 23:56:41
There are several good blogs about how to implement the repository pattern together with the unit-of-work pattern using generic classes. Implementing a Data Access Layer with Entity Framework 6.1 Implementing the Repository and Unit of Work Patterns The Idea is, to define a generic interface IRepository and a class Repository that hides how the data is actually accessed. It can be accessed using Entity Framework DbContext, or maybe the repository is an in memory collection for unit testing. public interface public interface IRepository<T> where T : class { T GetById(int Id); void DeleteById

EF - and repository pattern - multiple contexts

旧巷老猫 提交于 2019-11-27 23:01:25
问题 I've faced some troubles with context in EF in ASP.MVC2. I thought that best way to improve some operation on DataBase i've created Repository. My repo class adds, deletes, select many items so i don't need to write (using <name>Context = new (... etc ...) ) { ... } Repository eliminates initializing context for every operation, but don't dispose the context. What is the best way to manage contexts? If i create other repository class and try to do any operation which will need objects from

Decouple unit of work from services or repo

拈花ヽ惹草 提交于 2019-11-27 18:54:05
I am trying to decouple my unit of work from my services or repository so that I wont have to touch the UoW code whenever I wish to add a new service. How do I do this? _categoryService = _unitOfWork.Get<ICategoryService>(); so instead of _unitOfWork.CategoryService.Add(category) I can just say; _categoryService.Add(category); I am trying to decouple my unit of work from my services or repository so that I won’t have to touch the UoW code whenever I wish to add a new service Well, that’s a good start! ;-) The solution I am presenting is not the one and only possible solution, there are several

Repository pattern: One repository class for each entity?

余生颓废 提交于 2019-11-27 18:46:54
Say you have the following entities defined in a LINQ class: Product Customer Category Should I have one repository class for all: StoreRepository ... or should I have: ProductRepository CustomerRepository CategoryRepository What are the pro & cons of each? In my case, I have several "applications" within my solution... the Store application is just one of them. Here's my point of view. I'm a strict follower of the Repository pattern. There should be 3 methods that take a single entity. Add, Update, Delete, generically defined. public interface IRepository<T> { void Add(T entity); void Update

Using The Repository Pattern, Is It Best To Save Parent and Children Objects Together Or Separately?

≯℡__Kan透↙ 提交于 2019-11-27 18:39:59
问题 Having a parent object Employee with a list of Address child objects: class Employee { List<Address> addresses; } and a Repository method: void Insert(Employee); Should the code within this repository attempt to save the parent Employee as well as the child Address objects, or should separate repositories handle the parent and children objects? If separate repositories, then when saving the Employee object and its children within the client code, should this be separate calls at that level,

Generic Repository for SQLite-Net in Xamarin Project

守給你的承諾、 提交于 2019-11-27 17:44:43
I am wondering if there is a way to write a generic repository for my Xamarin project versus writing a different Repository for each entity in my object. The Xamarin Tasky Pro example have one Repository for the Task entity because that is the only entity it has. In my own project I have more than one Entity, so my question is how can I make the following Customer Repository to become generic so that the ProductManager, EmployeeManager, etc can use it. If you know of an example or a blog post please point me to the right direction namespace App.DataLayer { public class CustomerRepository {