Entity Framework で UnitOfWork パターンを使用して、以下のコードを使用して DbContext を公開します。私の質問は、 Ninject で Context インスタンスを取得することは可能ですか?
IUnitOfWork
public interface IUnitOfWork<C> : IDisposable
{
int Commit();
C GetContext { get; set; }
}
UnitOfWork
public class UnitOfWork<C> : IUnitOfWork<C> where C : DbContext
{
private bool _disposed;
private readonly C _dbContext = null;
public UnitOfWork()
{
GetContext = _dbContext ?? Activator.CreateInstance<C>();
}
public int Commit()
{
return GetContext.SaveChanges();
}
public C GetContext
{
get;
set;
}
[...]
現在、NinjectWebCommon内
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IUnitOfWork<MyDbContext>>().To<UnitOfWork<MyDbContext>>().InRequestScope();
kernel.Bind<IEmployeeRepository>().To<EmployeeRepository>();
}
を使用せずに、 Ninjectを介してDbContextインスタンス_dbContext ?? Activator.CreateInstance<C>();
を取得することはできますか?