Ninjectを使用したデータアクセスにNopCommerceコードを再利用しようとしています。私のQ:不特定のジェネリック型をオブジェクトに注入するにはどうすればよいですか?NopCommerceがAutofacを使用していることは知っています。
オブジェクトの説明:MyController
リポジトリ()を保持するコントローラ()がありますIRepository<T>
。このリポジトリは、EfRepository<T>
ninjectコマンドを使用して挿入されますkernel.Bind(typeof(IRepository<>)).To(typeof(EfRepository<>))
。汎用のEfRepository
holdstypeof 。
ジェネリック型をに渡しませんが、それでも注入されます。Ninjectを使用してどのように行われますか?IDbContext
DbContext
EfRepository
IDbContext
コード;
public class MyController : Controller
{
//a repository --> injected as EfRepository<> using generic injection using the command:
//kernel.Bind(typeof(IRepository<>)).To(typeof(EfRepository<>));
private readonly IRepository<Account> _repository;
}
public class EfRepository<T> : IRepository<T> where T : BaseEntity
{
private IDbContext _context; //<<== How do I inject <T> to IDbcontext?
}
public interface IDbContext
{
IDbSet<T> Set<T>() where T : BaseEntity;
}