我使用Spring.net依赖注入Framwork更新了我的项目。然后我继续集成AOP以启用简单的日志记录/跟踪机制。我的app.config中有一个循环dependendy的问题,但我解决了这个问题:
<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窗口的Model对象:
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();
}
}
但是如果发生“模型”对象的更改,我的WPF窗口就不再更新了!该物业发生了变化抛出PropertyChanged事件并且某人已订阅它。但是没有人试图获得Property值。跟踪/日志记录机制有效,get_Customer()
仅在启动时调用一次,然后再不调用。我不明白。 Spring.Aop.Framework.ProxyFactoryObject
应该将每个事件从目标对象转移到所有订阅者,不是吗?如果这不是问题并且事件到来,那么财产中的问题是什么? Proxy对象是否缓存了目标的属性?我只是不明白。
app.config中的注释行没有AOP。如果我评论上面的行并取消注释该行,一切正常。
如果您有任何想法,请告诉我。我希望我提供了足够但不太多的信息。如果您需要更多信息,我很乐意提供。
答案 0 :(得分:0)
您的上一条评论让我想起了this question。在他的回答中,Mark Pollack(Spring开发人员)建议将其放入您的配置中:
<aop:config proxy-target-type="true">
这将创建基于继承的代理。默认情况下,Spring AOP为您的类创建基于合成的代理,因此不会拦截任何内部方法,因为实例具有对自身的引用,而不是对其Spring创建的代理的引用。
请注意,事件不会自动从目标传播到代理。这(可能)是为什么模型中的更改不会传播到wpf窗口:模型会触发属性更改,但是窗口绑定到代理。在问题spring-aop-mvvm-foundation-propertychanged中,我试图详细解释这一点,并提出了(hackish)解决方法。