Questions tagged [irepository]

IRepository is just an interface that you create. It allows you to "decouple" your repositories from real implementations.

Decoupling is good because it means your code...:

Your code is much more reusable. This is just plain good. Your code can use Inversion of Control (or Dependency Injection). This is good to keep your concerns well separated. It is especially good because this allows Unit Testing... Your code can be Unit Tested. This is especially good in large projects with complex algorithms. It is good everywhere because it increases your understanding of the technologies you are working with and the domains you are trying to model in software. Your code becomes built around best practices, following a common pattern. This is good because it makes maintenance much easier.

More details: https://stackoverflow.com/a/4535781

46 questions
12
votes
3 answers

Am I using IRepository correctly?

I'm looking to use the IRepository pattern (backed by NHibernate, if it matters) in a small project. The domain is a simple one, intentionally so to allow me to focus on understanding the IRepository pattern. The lone domain class is Movie, with…
Grant Palin
  • 4,546
  • 3
  • 36
  • 55
11
votes
3 answers

Are we all looking for the same IRepository?

I've been trying to come up with a way to write generic repositories that work against various data stores: public interface IRepository { IQueryable GetAll(); void Save(T item); void Delete(T item); } public class…
Daniel
11
votes
2 answers

Fake Assemblies show warnings when generating shims for Interface and stubs for sealed types

I have a build configured with CI post which some tests are run. Although the tests run successfully, the build shows warnings: : Cannot generate stub for StructuremapMvc: type is sealed. : Cannot generate shim for IUnitOfWork: type is an…
Tinu
  • 695
  • 7
  • 12
4
votes
2 answers

Repository and Immutable objects?

I may be doomed by an impedence mismatch, but I'm trying to reconcile examples I've seen for IRepository and immutable objects. I'm working on a cataloging application where hundrds of web requests operate on a 'working set' of products - a subset…
n8wrl
  • 19,439
  • 4
  • 63
  • 103
3
votes
1 answer

How To Write CRUD Unit Tests for Moq and Linq-to-Sql

I am just getting involved in Moq and unit testing, so forgive me if this seems obvious (a quick search through SO didn't show me anything like this). I have an interface with the following proposed member: void AddFeed(Feed feed); That I would…
KevDog
  • 5,763
  • 9
  • 42
  • 73
3
votes
1 answer

What's the correct way to instantiate an IRepository class from the Controller?

I have the following project layout: MVC UI |...CustomerController (ICustomerRepository - how do I instantiate this?) Data Model |...ICustomerRepository DAL (Separate Data access layer, references Data Model to get the…
djdd87
  • 67,346
  • 27
  • 156
  • 195
3
votes
1 answer

concrete sense of IRepository vs Repository if I do not do unit tests with mocks

I have this: public interface IRepository where T : class { void Delete(T entity); void Add(T entity); void Attach(T entity); void Detach(T entity); void SaveChanges(); } now for every of my Entity I make concrete classes…
msfanboy
  • 5,273
  • 13
  • 69
  • 120
3
votes
1 answer

How to use IRepository in Orchard with int key (NOT IDENTITY)

I'm using Orchard IRepository to manage data and save to db... that's what I'm trying to do. My class is: public class SocietaRecord { public virtual int Id { get; set; } public virtual string Club { get; set; } public virtual string…
manudea
  • 371
  • 2
  • 15
2
votes
2 answers

How can I use Expression in NHibernate?

I have read the very good blog post of Rob Conery Crazy Talk: Reducing ORM Friction How can I generalize this interface so I can implement it with NHibernate? using System; using System.Collections; using System.Linq; using…
Mariano
  • 2,928
  • 6
  • 25
  • 28
2
votes
1 answer

ninject inject iunitofwork to repository scoped attribute

Let me start with my current setup, and then explain what I am trying to achieve. We are using NHibernate and trying to implement the IRepository/IUnitOfWork pattern with Ninject. It should ideally work generically for whatever application is using…
cjablonski76
  • 173
  • 1
  • 13
2
votes
1 answer

How to design multiple repositories that access the same real-time data using EF?

I am actually looking for some help on learning the ropes on designing multiple Repositories that will access the same database using EF. I have seen sample code where each repository has it's own private DBContext, but am having difficulty with…
yardpenalty.com
  • 1,244
  • 2
  • 17
  • 32
1
vote
1 answer

How to manage connections when using DbModelBuilder in Entity Framework?

I am writing an IRepository and IUnitOfWork wrapper for an EF4 Fluent schema. In this design, a DbCompiledModel is created once per application lifecycle (Like an NHibernate ISessionFactory). The DbCompiledModel expects an existing database…
duck9
  • 406
  • 3
  • 18
1
vote
1 answer

Why mocking a Repository requires a virtual function and mocking IRepository overrides the existing function?

I am doing unit testing using NUnit and Moq framework. When I try to mock the IRepository using mockRepo.Setup(x=>x.GetStr(It.IsAny)()).Returns(str) then the method which is to be tested gets overridden inside Repository class and the build fails.…
Krits
  • 85
  • 9
1
vote
1 answer

Adding global session filter to repository entity

I need to add a global filter to a repository entity, i.e. it has to be applied everywhere this entity is accessed on Application service layer. My filter contains two conditions. Whereas adding the first condition, which depends on a constant, is…
Alexander
  • 1,152
  • 1
  • 16
  • 18
1
vote
1 answer

MongoDB IRepository db Connections

This is what I have so far with regards to my IRepository for MongoDB and was wondering whether or not I'm on the right lines? public abstract class Repository : IRepository { private const string _connection =…
Gaz
  • 1,249
  • 3
  • 19
  • 37
1
2 3 4