2
我需要根据外部条件建立要在运行时解析的实例名称。我如何定制Unity如何解析实例?
Unity中有一个扩展点,我可以使用这个扩展点吗?还是应该使用工厂?
例如:
container.RegisterType<IStrategy, FooStrategy>("FooStrategy");
container.RegisterType<IStrategy, BarStrategy>("BarStrategy");
var foo = container.Resolve<IStrategy>(); // would like to extend here to select the correct type to resolve.
Assert.IsTrue(foo.GetType() == typeof (FooStrategy));
您在决定做出该决定时有哪些信息?容器不能只是猜测你需要什么。 – Steven
@Steven,这就是为什么我需要扩展它,我需要添加一些关于如何解决IStrategy类型的逻辑。 – shenku