public partial class CTMSEntitiesModel : OpenAccessContext, ICTMSEntitiesModelUnitOfWork
{
public CTMSEntitiesModel(string connection)
:base(connection, backend, metadataSource)
{ }
// there are more IQueryable requests here
}
public interface ICTMSEntitiesContext : ICTMSEntitiesModelUnitOfWork
{
FetchStrategy FetchStrategy { get; set; }
}
public interface ICTMSEntitiesModelUnitOfWork : IUnitOfWork
{
//all the IQueryable requests are here
}
我需要將ICTMSEntitiesContext綁定到CTMSEntitiesModel。我會怎麼做呢?當我這樣做時,我做錯了什麼?它拋出一個InvalidCastException。Ninject無效投射異常
kernel.Bind(typeof(CTMSDAL.ICTMSEntitiesContext)).To(typeof(CTMSDAL.CTMSEntitiesModel)).InRequestScope()
.WithConstructorArgument("connection", System.Configuration.ConfigurationManager.ConnectionStrings["CTMS_MVCConnection"].ConnectionString);
我將不勝感激您提供的所有幫助! 謝謝, Safris
您的CTMSEntitiesModel實現了ICTMSEntitiesModelUnitOfWork而不是ICTMSEntitiesContext。在內核中設置合適的接口。綁定(..行或實現ICTMSEntitiesContext與你的上下文? –