- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过 nuget 安装了 Ninject,并在 NinjectMVC3 的 RegisterServices 方法(由 nuget 创建)中注册了我的绑定(bind)。按照我的代码:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IUnitOfWork>().To<UnitOfWork>();
kernel.Bind<IRepository<Action>>().To<ActionRepository>();
kernel.Bind<IRepository<ActionType>>().To<ActionTypeRepository>();
kernel.Bind<IRepository<City>>().To<CityRepository>();
kernel.Bind<IRepository<Country>>().To<CountryRepository>();
kernel.Bind<IRepository<Goods>>().To<GoodsRepository>();
kernel.Bind<IRepository<Media>>().To<MediaRepository>();
kernel.Bind<IRepository<MediaType>>().To<MediaTypeRepository>();
kernel.Bind<IRepository<Ranking>>().To<RankingRepository>();
kernel.Bind<IRepository<Role>>().To<RoleRepository>();
kernel.Bind<IRepository<Sponsor>>().To<SponsorRepository>();
kernel.Bind<IRepository<State>>().To<StateRepository>();
kernel.Bind<IRepository<UserAccountInfo>>().To<UserAccountInfoRepository>();
kernel.Bind<IRepository<UserAction>>().To<UserActionRepository>();
kernel.Bind<IRepository<UserDeservesGoods>>().To<UserDeservesGoodsRepository>();
kernel.Bind<IRepository<UserGoods>>().To<UserGoodsRepository>();
kernel.Bind<IRepository<User>>().To<UserRepository>();
kernel.Bind<IUserService>().To<UserService>();
kernel.Bind<IAccountService>().To<AccountService>();
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
}
这是我的家庭 Controller :
readonly IRepository<Ranking> repoRanking;
public HomeController(IRepository<Ranking> repoRanking)
{
this.repoRanking = repoRanking;
}
当我执行 HomeController 时,出现以下异常:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Ninject.ActivationException: Error activating IRepository{Ranking}
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IRepository{Ranking} into parameter repoRanking of constructor of type HomeController
1) Request for HomeController
Suggestions:
1) Ensure that you have defined a binding for IRepository{Ranking}.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
我做错了什么?
最佳答案
您是否创建了默认模块来设置绑定(bind)而不是在注册服务方法中?
public class DefaultModule : NinjectModule {
public override void Load() {
Bind<IProductService>().To<ProductService>().InTransientScope();
}
}
然后在您的 Global.asax 文件中执行此操作:
protected override IKernel CreateKernel() {
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}
关于ninject - 在我的 MVC3 中使用 Ninject 时,我得到一个 Ninject.ActivationException : Error activating IRepository{Ranking} installed via Nuget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9880037/
我见过两种不同的创建通用存储库的方法。这两种方法(优点和缺点)之间有什么区别?请忽略方法上的差异,因为我对 之间的差异感兴趣 public interface IRepository where T
我正在为我的 mvc web 应用程序寻找一个简单的 IRepository 接口(interface),我在周围做了很多搜索,有多少人就有多少意见。所以我决定请教专家 如果能推荐一个常用的IRepo
我试图从基础开始,但无法理解如何创建此最小起订量对象。 public class TestRefMedicalSpecialty { private Mock> mockRefMedical
我已经为多个域实现了 IRepository 接口(interface),但我不知道如何调用具体方法。 代码如下: public interface IRepository where T : cla
我知道有一个 Unit Of Work 是在抽象之上有一个抽象 (DbContext),这肯定是一种反模式,或者至少不是必要的。 我有以下问题: 我有一个像这样的通用 IRepository: pub
我希望在一个小项目中使用 IRepository 模式(由 NHibernate 支持,如果它重要的话)。域是一个简单的域,有意让我专注于理解 IRepository 模式。单独的域类是 Movie,
我想知道使用 IRepository 模式处理关系数据的推荐方法是什么。 我的数据库有下表,列名在括号中: 计划(PlanId、名称、创建日期、修改日期、ViewId) 区域(AreaId、名称、nT
我正在设计我的 ASP.NET MVC 应用程序,我遇到了一些有趣的想法。 我见过的许多示例都描述和使用了存储库模式 ( IRepository ),所以这就是我在学习 MVC 时所做的方式。 现在我
当实际加载数据时,我对使用“IRepository 模式”时感到有些困惑。 目前我有这样的事情: public class MainViewModel : ViewModelBase { //
我使用提到的存储库编写了以下方法在以下博客文章 (http://www.codecapers.com/post/Using-RavenDB-with-ASPNET-MVC.aspx) 中使用 Rave
我是 Repository 概念的新手,遇到了一些问题。我在我的 MVC 应用程序中创建了简单的存储库类。 public interface IRepository where TEntity
我想模拟一个内部存储库的工作单元接口(interface),用于单元测试目的。到目前为止,我可以像下面那样做。 namespace Liquid.Service.UnitTest { usin
什么是 IRepository?为什么使用它,简短的例子不会有什么坏处。 最佳答案 MVC 促进关注点分离,但这并不止于 MVC 级别。 数据访问本身就是一个问题。应该是在MVC的M位,即模型中完成。
可以说我的 IService 拥有 IRepository 拥有的一切,而且还有一些特定的操作吗? 代码如下: public interface IRepository { T Add(T E
我已经实现了存储库模式并且效果很好。 public interface IServiceRepository { User GetUser(int id); User GetUser(
我正在使用通用存储库接口(interface),它允许我添加、查找、更新和删除不同类型的对象。然后我实现了两个具体的存储库,并且可以在不更改应用程序的情况下切换它们。一切都奇妙地脱节。但我遇到了一个障
我一直在尝试想出一种方法来编写适用于各种数据存储的通用存储库: public interface IRepository { IQueryable GetAll(); void Sav
在典型的三层系统中,GUI->DOMAIN->DAL,IRepository 属于哪里?它属于 DOMAIN 还是 DAL。我对正交性和服务层了解不够,不知道有什么区别。(编辑)请允许我澄清一下。 I
我有以下项目布局: MVC UI |...CustomerController (ICustomerRepository - how do I instantiate this?) Data Mode
在 Orchard CMS 中使用 IRepository<>很常见。 所以我问自己,使用 IRepository<> 有什么好处?及其 Fetch()方法而不是简单地使用 Linq to SQL查询
我是一名优秀的程序员,十分优秀!