Note that there are some explanatory texts on larger screens.

plurals
  1. PONinject EF4, Repository and Unit of Work
    primarykey
    data
    text
    <p>I have several projects in my solution which access the same data so I am implementing data access later in a separate project. Currently I am using EF4, a generic repository and a Unit Of Work pattern. I have designed my data access to support dependency injection and I want to use Ninject. Here is a sample of what I have so far</p> <pre><code>public class Account { public int Id { get; set; } public Guid WebId { get; set; } public string Firstname { get; set; } public string Lastname { get; set; } public string Email { get; set; } public string Address { get; set; } public string Mobile { get; set; } } public interface IRepository&lt;T&gt; { IEnumerable&lt;T&gt; Get(Expression&lt;Func&lt;T, bool&gt;&gt; filter, Func&lt;IQueryable&lt;T&gt;); T GetById(int id); void Update(T dinner); void Insert(T dinner); void Delete(int id); void Save(); } </code></pre> <p>I also have a Repository Implementation which I won't post it here for space.</p> <p>My UnitOfWork looks like this</p> <pre><code>public class UnitOfWork { private Repository&lt;Account&gt; _accountRepository; public IRepository&lt;Account&gt; AccountRepository { get { if (this._accountRepository == null) { _accountRepository = new Repository&lt;Account&gt;(); } return _accountRepository; } } } </code></pre> <p>How and where do I set up ninject to auto resolve my Repository so I can use the interface and not need to instantiate it in my unit of work. Is this the right thing to do or am I getting the point of DI all wrong? Here is what I think I want my unit of work class to look like</p> <pre><code>public class UnitOfWork { IKernel _kernel; public UnitOfWork() { _kernel = new StandardKernel(); } private IRepository&lt;Account&gt; _accountRepository; public IRepository&lt;Account&gt; AccountRepository { get { if (this._accountRepository == null) { _accountRepository = _kernel.Get&lt;IRepository&lt;Account&gt;&gt;();; } return _accountRepository; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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