Ninject和配置 [英] Ninject and configuration
问题描述
我以前用的城堡作为一个IoC但我不得不在同一个项目,所以我搬到Ninject使用NHibernate /城堡(IOC)的一个问题。现在去的问题,我有这个类:
I used to use Castle as an IoC but I had a problem using Nhibernate/Castle(IoC) in the same project so i moved to Ninject. Now to get to the question, I have this class:
class CustomModule : NinjectModule
{
public override void Load()
{
Bind<Interfaces.ICafe>().To <Concrete.Tea>();
}
}
混凝土
是一个单独的项目和 Interfaces.ICafe
是一个不同的项目。随着城堡我用来给开发者接口DLL,并请他执行一项新的具体实现该接口并配置与在app.config,所以不管他怎样实现类的名字仍然有效,因为他已经写在在app.config,所以如果他弄得像 Concrete.Coffee
将仍然工作。
Concrete
is a separate project and Interfaces.ICafe
is a different project. With Castle I used to give a developer the interfaces DLL and ask him to implement a new concrete implementing that interface and then configure that with the app.config, so no matter what class name he implements it still works because he has to write that in the app.config, so if he made it like Concrete.Coffee
it would still work.
但随着Ninject他必须做出具有相同的类名茶经的具体以使其工作,否则它不会工作,因为它是硬编码。
But with Ninject he has to make a concrete with the same class name "Tea" in order to make it work otherwise it wouldn't work because it is hard coded.
我是新来的Ninject我知道有可能是我丢失的东西?
I'm new to Ninject and i know there is probably something I'm missing ?
推荐答案
如果你想避免引用具体实施中,可以使用的约定扩展加载在运行时的执行。
If you want to avoid referencing the concrete implementation, you can use the conventions extension to load the implementation at runtime.
-Ian
这篇关于Ninject和配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!