I'm still on my eternal quest to build (and understand) modern programming convention of decoupling, IoC, DI, etc. I'm to the part where I am trying to figure out how to build a repository. I've examined the post at Database abstraction layer design - Using IRepository the right way? which was very helpful, but I've still got some problems that are just befuddling me all the way.
I have my program in now 4 layers...
Web (Project | ASP.NET MVC Application) - References Models.dll and Persistence.dll
Models (Domain Objects)
Persistence (Fluent nHibernate Mapping of Domain Objects)
Utilities (Providers, Repositories)
Now then, I'm trying to write up a simple Membership Repository. My first task... ?
Check to see if an email address exists when someone tries to register. That seemed all well and good - so I go to try and figure out where to place this.
At first though, I would just place it inside of the MembershipProvider
class CreateUser
method. This, however, resides in the Utilities project. So far, Utilities has no knowledge of nHibernate. Only the Persistence Project has any knowledge of nHibernate.
So then, my CreateUser
method needs to query my database. So what's the best practice here? Do I create a UserRepository
in the Persistence
project, and just make an entire method called CheckEmail
? Or do I simply add the nHibernate .dll's to my Utilities
project, and write session lookup within the Provider?
It seems like more work to make repositories in my Persistence Project that do specific actions than it is to make the providers. Why am I even making the Providers if I have to make Repositories for them? Isn't the purpose of all of these new methods to stop code repetition? But it feels like to keep things 'separate' I have to write the same code 2 or 3 times. What is the best practice here?