单击正在创建的站点上的链接时,出现了此错误
Error activating IEntityCache using binding from IEntityCache to EntityCache
No constructor was available to create an instance of the implementation type.
Activation path:
4) Injection of dependency IEntityCache into parameter entityCache of constructor of type AlbumRepository
3) Injection of dependency IAlbumRepository into parameter albumRepository of constructor of type AlbumService
2) Injection of dependency IAlbumService into parameter albumService of constructor of type AlbumController
1) Request for AlbumController
Suggestions:
1) Ensure that the implementation type has a public constructor.
2) If you have implemented the Singleton pattern, use a binding with InSingletonScope() instead.
EntityCache是一个没有公共建筑的单身人士。所以我就是这么做的
kernel.Bind<IAlbumService>().To<AlbumService>();
kernel.Bind<IAlbumRepository>().To<AlbumRepository>();
kernel.Bind<IDbSetWrapper<Album>>().To<DbSetWrapper<Album>>();
kernel.Bind<IEntityCache>().To<EntityCache>().InSingletonScope();
我做错了什么?
编辑
这是我的存储库:
public AlbumRepository(DatabaseContext context, IDbSetWrapper<Album> dbSetWrapper, IEntityCache entityCache)
: base(context, dbSetWrapper, entityCache)
如何通过IEntityCache?
发布于 2014-02-09 22:22:51
EntityCache是一个没有公共建筑的单身人士。
如何期望您的DI框架能够实例化这个类?如果您的类没有默认的公共构造函数或使用已经在DI中注册的参数的构造函数,这就不可能起作用。
如果类没有公共构造函数,则可能需要自己提供特定实例:
kernel
.Bind<IEntityCache>()
.ToMethod(context => ...return your specific instance here...)
.InSingletonScope();
例如:
kernel
.Bind<IEntityCache>()
.ToMethod(context => EntityCache.Instance)
.InSingletonScope();
https://stackoverflow.com/questions/21665839
复制相似问题