2011-03-29 2 views
1

저는 Spring.net 의존성 삽입 프레임 워크로 프로젝트를 업데이트했습니다. 그런 다음 간단한 로깅/추적 메커니즘을 사용하기 위해 AOP를 통합하는 작업을 계속했습니다. 나는 나의의 app.config에서 원형 dependendy 몇 가지 문제가 있었다, 그러나 나는 그것을했다 :Spring.net AOP가 WPF 데이터 바인딩을 방해하는 것 같습니다.

내 클래스는 다음과 같습니다
<spring> 
<context> 
    <resource uri="config://spring/objects"/> 
</context> 
<objects xmlns="http://www.springframework.net"> 
    <object id="loggingAroundAdvice" type="SetupBuilder.LoggingAroundAdvice"/> 
    <object id="myServiceObjectTarget" type="SetupBuilder.SetupBuilderModelView, SetupBuilder"> 
    <!--<object name="Model" type="SetupBuilder.SetupBuilderModelView, SetupBuilder">--> 
    <constructor-arg index="0" ref="MasterData"/> 
    <property name="FileSelection" ref="FileSelection"/> 
    <property name="Persistence" ref="Persistence"/> 
    <property name="Distributor" ref="Distributor"/> 
    <property name="Document" ref="Document"/> 
    <property name="StatusWindow" ref="StatusWindow"/> 
    </object> 
    <object name="Model" type="Spring.Aop.Framework.ProxyFactoryObject"> 
    <property name="target" ref="myServiceObjectTarget"/> 
    <property name="interceptorNames"> 
     <list> 
     <value>loggingAroundAdvice</value> 
     </list> 
    </property> 
    </object> 
    <object name="MasterData" type="VMRedistMasterData.Implementation.VMRedistMasterDataImpl, VMRedistMasterData"/> 
    <object name="FileSelection" type="SetupBuilder.OpenAndSaveDialog, SetupBuilder"/> 
    <object name="Persistence" type="VMRedistDelivery.Implementation.Persistence.DeliveryPersistence, VMRedistDelivery"/> 
    <object name="Distributor" type="VMRedistDelivery.Implementation.Distribution.Distributor, VMRedistDelivery"/> 
    <object name="Document" type="Word2010ReleaseDocument.Word2010ReleaseDocument, Word2010ReleaseDocument"/> 
    <object name="StatusWindow" type="SetupBuilder.WpfStatusWindow, SetupBuilder"> 
    <constructor-arg index="0" ref="Model"/> 
    </object> 
</objects> 

: 여기

public interface ISetupBuilderModelViewDependencies 
{ 
    IVMRedistMasterData MasterData { get; set; } 
    IFileSelection FileSelection { get; set; } 
    IVMRedistPersistence Persistence { get; set; } 
    IVMRedistDistributor Distributor { get; set; } 
    IVMRedistReleaseDocument Document { get; set; } 
    IStatusWindow StatusWindow { get; set; } 
} 

public class SetupBuilderModelView : ISetupBuilderModelView, ISetupBuilderModelViewDependencies, INotifyPropertyChanged 
{ 
... 
    public string Customer 
    { 
     get { return customer; } 
     set 
     { 
      customer = value; 
      FirePropertyChanged("Customer"); 
     } 
    } 
... 
} 

할당 모델 객체입니다 내 기본 WPF 창 :

public partial class App : Application 
{ 
    private void Application_Startup(object sender, StartupEventArgs e) 
    { 
     var context = ContextRegistry.GetContext(); 

     var setupBuilderWindow = new SetupBuilderWindow(context.GetObject("Model") as ISetupBuilderModelView); 
     // SetupBuilderWindow needs an ISetupBuilderModelView argument.        
     setupBuilderWindow.Show(); 
    } 
} 

"Model"개체의 변경 사항이 발생하면 내 WPF 창 더 이상 업데이트되지 않습니다! 속성이 변경되었습니다. PropertyChanged 이벤트가 throw되고 사람이 구독했습니다. 그러나 아무도 Property 값을 얻으려고하지 않습니다. 추적/기록 메커니즘이 작동하면 get_Customer()은 시작시 한 번만 호출 된 다음 다시는 호출되지 않습니다. 나는 그것을 얻지 않는다. Spring.Aop.Framework.ProxyFactoryObject은 모든 이벤트를 대상 개체에서 모든 구독자에게 전송해야합니까? 그것이 문제가 아니며 이벤트가 도착하면, 부동산에 문제가 있습니까? Proxy 객체가 대상의 속성을 캐싱하고 있습니까? 나는 단지 그것을 얻지 않는다.

app.config의 주석 처리 된 행에 AOP가 없습니다. 위의 행에 주석을 달고 그 행의 주석 처리를 제거하면 모든 것이 정상적으로 작동합니다.

혹시 궁금한 점이 있으면 알려 주시기 바랍니다. 나는 너무 많은 정보를 충분하게 제공했으면 좋겠다. 추가 정보가 필요하면 제공해 드리겠습니다.

+0

myServiceObjectTarget 객체를 Model 객체로 이동하지 못했습니다. 팩토리를 프로그래밍 방식으로 호출하면 작동하지 않습니다. – dutop

+0

공장에서 만든 오브젝트는 생각만큼 정상적인 오브젝트에 연결하기가 힘듭니다. _only_는 WPF 창에 의한 변경에 반응합니다. SetupBuilderModelView 클래스 내의 변경 내용이 나타나지 않습니다. – dutop

답변

0

마지막 코멘트는 this question을 생각 나게합니다. 그의 답변에서, Mark Pollack (Spring 개발자)은 이것을 다음과 같이 사용자의 구성에 넣으라고 제안합니다.

<aop:config proxy-target-type="true"> 

이렇게하면 상속 기반 프록시가 생성됩니다. 기본적으로 Spring AOP는 클래스에 대한 컴포지션 기반 프록시를 생성하므로 인스턴스에 자체적으로 참조가 있고 Spring에서 작성한 프록시가 아닌 내부 메소드가 인터셉트되지 않습니다.

이벤트는 대상에서 프록시로 자동 전파되지 않습니다. 이것은 아마도 모델의 변경 사항이 wpf 창으로 전파되지 않는 이유 일 것입니다. 모델은 속성 변경을 실행하지만 윈도우는 프록시에 바인딩됩니다. 질문에 spring-aop-mvvm-foundation-propertychanged 나는 이것을 자세히 설명하고 (해킹 된) 해결 방법을 제안했습니다.

+0

이것이 효과가 있다면 정말 궁금합니다. 현재 문서 ([aop 13.6] (http://www.springframework.net/doc-latest/reference/html/aop.html#aop-proxy-mechanism))는 그렇지 않다고 말하지만, Mark의 대답은 그것이 작동 할 것이라고 제안합니다. – Marijn

+0

가상으로 인터셉트하려는 메서드/속성을 반드시 선언해야합니다. – Marijn

+0

그리고 스프링 1.3.1 이상을 사용해야합니다. – Marijn