Asp.net mvc 2 Ninject 2.0:根据实现传递不同的参数

Asp.net mvc 2 Ninject 2.0:根据实现传递不同的参数,asp.net-mvc-2,dependency-injection,ninject,ninject-2,constructor-injection,Asp.net Mvc 2,Dependency Injection,Ninject,Ninject 2,Constructor Injection,我刚刚开始使用带有ASP.NET MVC 2的Ninject 2.0。 因此,我有一个接口IMongoRepository和类MongoRepository MongoRepository接收参数字符串集合 根据要使用的集合,我在MongoRepository的参数中传递不同的值。 我希望我的措辞是正确的,但是如何根据我使用的控制器映射不同的参数呢 例如,在文章controller中,我称之为: _articlesRepository = new MongoRepository("Article

我刚刚开始使用带有ASP.NET MVC 2的Ninject 2.0。 因此,我有一个接口IMongoRepository和类MongoRepository

MongoRepository接收参数字符串集合

根据要使用的集合,我在MongoRepository的参数中传递不同的值。 我希望我的措辞是正确的,但是如何根据我使用的控制器映射不同的参数呢

例如,在文章controller中,我称之为:

_articlesRepository = new MongoRepository("Articles");
_pagesController = new MongoRepository("Pages");
在PageController中,我会调用:

_articlesRepository = new MongoRepository("Articles");
_pagesController = new MongoRepository("Pages");
我想做的就是进行构造函数注入,然后传入IMongoRepository。 有什么想法或建议吗

顺便说一下,我只是在了解国际奥委会/国际奥委会;所以,我愿意听取国际奥委会忍者的任何建议! 谢谢

尝试以下操作:

Bind<IMongoRepository>().To<MongoRepository>().WhenInjectedInto<ArticleController>().WithConstructorArgument("topic", "Article");
Bind<IMongoRepository>().To<MongoRepository>().WhenInjectedInto<PagesController>().WithConstructorArgument("topic", "Pages");
Bind().To().whenInjectedTo().WithConstructorArgument(“主题”、“文章”);
使用构造函数参数(“主题”、“页面”)将()绑定到();
假设构造函数的参数被称为
topic

,那么这个链接看起来很有希望!