간단한 인젝터 소비자 서비스 유형, 이런 식으로 뭔가를 기반으로 :등록 장식 조건부 나는 일부 소비자는 자신의 유형에 특정 장식을 기반으로합니다 방식으로 <code>IService</code>을 장식 할
container.Register<IService, Service>();
container.RegisterDecorator<IService, ServiceWithCaching>();
container.RegisterDecoratorConditional<IService, ServiceWithLogging>
(ctx => ctx.Consumer.ServiceType ==
typeof(IConsumerThatNeedsDecoratedService));
container.Register<IConsumerThatNeedsServiceWithLogging, Consumer1>();
container.Register<INormalConsumer, Consumer2>();
곳 모두 ServiceWithCaching
및 ServiceWithLogging
은 생성자에서 IService
을 가져 와서 IService의 인스턴스를 래핑하고 내부적으로 호출 한 다음 다른 작업을 수행합니다 (예 : 캐싱, 로깅).
Consumer1
및 Consumer2
모두 생성자에 IService
을 수락합니다.
Consumer1
을 ServiceWithLogging
및 Consumer2
의 인스턴스를 ServiceWithCaching
으로 삽입하고 싶습니다. 원하는 동작은 Consumer1
이 IService
의 인스턴스를 사용하여 결과를 캐시하는 반면 Consumer2
은 IService
의 인스턴스를 사용하므로 두 캐시 모두 로그 호출 결과입니다.
Simple Injector에서 가능한가요? 알려진 해결 방법이 없습니까?