Note that there are some explanatory texts on larger screens.

plurals
  1. POStill lost on Repositories and Decoupling, ASP.NET MVC
    text
    copied!<p>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 <a href="https://stackoverflow.com/questions/2347337/database-abstraction-layer-design-using-irepository-the-right-way">Database abstraction layer design - Using IRepository the right way?</a> which was very helpful, but I've still got some problems that are just befuddling me all the way.</p> <p>I have my program in now 4 layers... </p> <blockquote> <p>Web (Project | ASP.NET MVC Application) - References Models.dll and Persistence.dll</p> <p>Models (Domain Objects)</p> <p>Persistence (Fluent nHibernate Mapping of Domain Objects)</p> <p>Utilities (Providers, Repositories)</p> </blockquote> <p>Now then, I'm trying to write up a simple Membership Repository. My first task... ? </p> <p>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.</p> <p>At first though, I would just place it inside of the <code>MembershipProvider</code> class <code>CreateUser</code> 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.</p> <p>So then, my <code>CreateUser</code> method needs to query my database. So what's the best practice here? Do I create a <code>UserRepository</code> in the <code>Persistence</code> project, and just make an entire method called <code>CheckEmail</code>? Or do I simply add the nHibernate .dll's to my <code>Utilities</code> project, and write session lookup within the Provider?</p> <p>It seems like <strong>more</strong> 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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload