从 Munq.Codeplex.com 的源选项卡获取最新版本。这个版本有一个视图改进,是我最熟悉的版本,我写的。
为了防止注册的循环引用,创建一个类项目,其中包括对 Munq.Interfaces 的尊重以及您希望注册的接口和实现。
创建一个实现IMunqConfig 的类。它有一种方法void RegisterIn(IIocContainer container)。实现这个方法。
public class MyRegistration : IMuncConfig
{
public void RegisterIn(IIocContainer container)
{
container.Register<IMyInterface>(c => new MyImplementation());
// OR
container.Register<IMyInterface, MyImplementation>();
// Repeat as required for each thing to register
}
}
然后在 global.asax
protected void Application_Start()
{
IocContainer = new Container();
Munq.COnfigurationLoader.FindAndRegisterDependencies(container);
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
这将在 bin 目录中搜索任何具有实现 IMunqConfig 的类的 dll,并在每个 dll 上执行 RegisterIn 方法。所以只需将注册 dll 放到 bin 目录中,注册就会自动发生:)
马修