首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尼尼特-注射单胎

尼尼特-注射单胎
EN

Stack Overflow用户
提问于 2014-02-09 22:20:30
回答 1查看 1.4K关注 0票数 1

单击正在创建的站点上的链接时,出现了此错误

代码语言:javascript
运行
复制
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是一个没有公共建筑的单身人士。所以我就是这么做的

代码语言:javascript
运行
复制
kernel.Bind<IAlbumService>().To<AlbumService>();
            kernel.Bind<IAlbumRepository>().To<AlbumRepository>();
            kernel.Bind<IDbSetWrapper<Album>>().To<DbSetWrapper<Album>>();
            kernel.Bind<IEntityCache>().To<EntityCache>().InSingletonScope();

我做错了什么?

编辑

这是我的存储库:

代码语言:javascript
运行
复制
public AlbumRepository(DatabaseContext context, IDbSetWrapper<Album> dbSetWrapper, IEntityCache entityCache)
            : base(context, dbSetWrapper, entityCache)

如何通过IEntityCache?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-09 22:22:51

EntityCache是一个没有公共建筑的单身人士。

如何期望您的DI框架能够实例化这个类?如果您的类没有默认的公共构造函数或使用已经在DI中注册的参数的构造函数,这就不可能起作用。

如果类没有公共构造函数,则可能需要自己提供特定实例:

代码语言:javascript
运行
复制
kernel
    .Bind<IEntityCache>()
    .ToMethod(context => ...return your specific instance here...)
    .InSingletonScope();

例如:

代码语言:javascript
运行
复制
kernel
    .Bind<IEntityCache>()
    .ToMethod(context => EntityCache.Instance)
    .InSingletonScope();
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21665839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档