2
외부 조건에 따라 런타임시 해결할 인스턴스의 이름을 빌드해야합니다.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