0

I'm working on using the Repository methodology in my App and I have a very fundamental question.

When I build my Model, I have a Data.dbml file and then I'm putting my Repositories in the same folder with it.... IE:

Data.dbml
IUserRepository.cs
UserRepository.cs

My question is simple. Is it better to build the folder structure like that above, or is it ok to simply put my Interface in with the UserRepository.cs?

Data.dbml
UserRepository.cs              which contains both the interface and the class

Just looking for "best practices" here. Thanks in advance.

Jason Berkan
  • 8,734
  • 7
  • 29
  • 39
Chase Florell
  • 46,378
  • 57
  • 186
  • 376

2 Answers2

2

General best practice is to have one class or one interface per file.

Here's the more generic discussion, which I think applies to your case: One class per file rule in .NET?

As a developer new to your project, I would appreciate knowing that IUserRepository exists--without having to fish through your UserRepository.cs file.

Community
  • 1
  • 1
Evan Nagle
  • 5,133
  • 1
  • 26
  • 24
0

Do whatever makes sense to you.

Personally I find browsing solutions for anything painful so I have hot keyed Goto Definition/Implementation and Resharpers FindUsages Go to Type, Go to File so I never have to click anything.

Combining interfaces and classes in one file makes sense if the class or interfaces are small.

Also if your following the Liskov substitution principal / a dependency injection strategy and general good design practices you would rarely be interacting with actual implementations anyway. Repositories should almost never be referred to by their concrete implementation.

John Farrell
  • 24,673
  • 10
  • 77
  • 110
  • Thanks for that. Can you please elaborate on `Repositories should almost never be referred to by their concrete implementation.`? – Chase Florell Jun 15 '10 at 03:48
  • @rockinthesixstring When you need to use a class you don't reference the concrete implementation you use the interface instead. So if you were to use dependency injection, your dependencies would not be the Repository, but the IRepository. – Min Jun 15 '10 at 04:02
  • so something like this? `Dim usr As UrbanNow.Core.IUserRepository = New UrbanNow.Core.UserRepository` – Chase Florell Jun 15 '10 at 04:44
  • he means use an IOC framework such as StructureMap/Ninject to handle the wiring-up in an external location (bootstrapper). Your controller/model only references the interfaces. – RPM1984 Jun 15 '10 at 05:03