title: Where does Unit Of Work belong w/ EF4, IoC (Unity), and Repository?
body: <p>I see several questions relating somewhat to this, but I still can't find the answer I'm looking for, so I'm posting my question.  If another question holds the answer (and I'm just not seeing it), please point me to it.</p>
  
  <p>I'm trying to figure out where my UnitOfWork belongs -- and specifically, gets created -- when using EF4 and Unity with the Repository pattern.</p>
  
  <p>Basically, I have a service that is used to implement my business logic.  This service constructor takes in the repository, so the service gets injected with my repository.   The service then uses the injected repository to carry out actions against the data store -- but I need to wrap these in a unit of work.</p>
  
  <p>My unit of work, however, needs to be injected with the EF4 context (or, in my case, and interface of the context -- IObjectContext).  And I'm not sure where the UoW should be created and injected w/ the context.</p>
  
  <p>Here are the possible options I can think of, none of which seem ideal:</p>
  
  <ul>
  <li><p>Include the UoW in the service constructor, thus having the service injected w/ the unit of work, which in turn is injected w/ my EF4 context.  But this seems wrong because I don't want my UoW created on every instance of the repository.</p></li>
  <li><p>Do an on-demand creation using container.Resolve to get an instance of the UoW, injecting my EF4 context.  This seems excessive having to constantly hit the IoC container, rather than already having access to the UoW.</p></li>
  <li><p>Inject the context directly into the service, allowing me to create a UoW(context).  This seems bad since I've now exposed the context to the service, and this should be isolated to the repository.</p></li>
  </ul>
  
  <p>So my question is, is one of these methods acceptable, or is there another method I'm not thinking of?</p>
  
  <p>Thanks in advance.</p>