RoboGuice 사용환경에서 AspectJ의 aspect 클래스에 모듈을 injection하는 방법입니다.
방법1. static 방식으로 injection
(1) 애스펙트 클래스에서 static 멤버변수로 선언
주입할 모듈을 static 멤버변수로 선언합니다.
@Inject protected static ContextScopedProvider<T> tProvider; // T는 @ContextSingleton이어야함
@Inject protected static ExceptionHandler exceptionHandler;//Singleton
(2) Guice 모듈 설정에서 static injection 처리
configure() 메소드에서 requestStaticInjection 메소드를 통해 주입합니다.
requestStaticInjection(ExceptionHandlingAspect.class);
그러나 이 방법은 권장하지 않습니다. Guice에서도 static injection은 deprecated될 것이라고 합니다.
http://code.google.com/p/google-guice/wiki/AvoidStaticState
방법 2. aspect 객체를 구하여 injection
aspect는 AspectJ에 의해 인스턴스화되며 우리가 직접 생성할 수 없습니다. 대부분의 경우 aspect는 싱글턴 객체이며, AspectJ는 싱글턴 aspect 객체를 참조할 수 있는 Aspects.aspectOf() 메소드를 제공합니다.
(1) 주입할 모듈을 애스펙트 클래스에 보통의 멤버변수로 선언
@Inject protected ExceptionHandler exceptionHandler;
(2) Guice 모듈 설정에서 requestInjection을 통해 injection 처리
requestInjection(org.aspectj.lang.Aspects.aspectOf(ExceptionHandlingAspect.class));
'Android' 카테고리의 다른 글
[RoboGuice] injection 이후 특정 메소드 실행 방법 (0) | 2012.04.29 |
---|---|
[RoboGuice] 어노테이션 활용 (0) | 2012.04.29 |
[안드로이드] RoboGuice 단점 보완 방안 (0) | 2012.04.19 |
[안드로이드] Non UI쓰레드에서 UI작업을 위한 올바른 Handler 생성법 (3) | 2012.04.19 |
[안드로이드] RoboGuice 2.0 메모 (0) | 2012.04.19 |