Inject same DataContext instance across several types with Unity

Posted by Sergejus on Stack Overflow See other posts from Stack Overflow or by Sergejus
Published on 2009-05-22T10:15:12Z Indexed on 2010/05/29 18:52 UTC
Read the original article Hit count: 252

Suppose I have IRepository interface and its implementation SqlRepository that takes as an argument LINQ to SQL DataContext. Suppose as well that I have IService interface and its implementation Services that takes three IRepository, IRepository and IRepository. Demo code is below:

public interface IRepository<T> { }

public class SqlRepository<T> : IRepository<T>
{
    public SqlRepository(DataContext dc) { ... }
}

public interface IService<T> { }

public class Service<T,T1,T2,T3> : IService<T>
{
    public Service(IRepository<T1> r1, IRepository<T2>, IRepository<T3>) { ... }
}

Is it any way while creating Service class to inject all three repositories with the same DataContext?

© Stack Overflow or respective owner

Related posts about c#

Related posts about dependency-injection