【发布时间】:2016-05-11 22:50:44
【问题描述】:
我有两个不同的IContext 实现在不同的程序集中(实际上它们在不同的解决方案中)。这些程序集都在一个父项目中使用。此父项目使用 SimpleInjector 进行 DI。
有没有办法让 Simple Injector 根据被注入的类的装配位置来注入/注册不同的实现?
在伪软糖代码中,类似于:
// if assembly/namespace of class being injected into is MyApp.ProjectFoo;
container.Register(typeof(IContext), typeof(FooContext));
// if assembly/namespace of class being injected into is MyApp.ProjectBar;
container.Register(typeof(IContext), typeof(BarContext));
【问题讨论】:
标签: c# dependency-injection simple-injector