J'essaie d'utiliser Spring.NET AOP dans mon projet pour la consignation, et deux conseils fonctionnent très bien, cependant, le troisième ne s'utilise pas du tout.Spring.NET n'utilise pas AOP AfterReturningAdvice
Voici mon câblage:
<!-- the "After" Advice -->
<object id="GraphicsContextManagerAfter" type="PicturetoolWeb.App.Advice.GraphicsContextManagerAfter, PicturetoolWeb.App">
</object>
<!-- The Proxy -->
<object id="PicturetoolWeb.ImageLib.Context.GraphicsContextManager" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="target" ref="GraphicsContextManagerTarget"/>
<property name="interceptorNames">
<list>
<value>GraphicsContextManagerAfter</value>
</list>
</property>
</object>
je puis obtenir l'instance GraphicsContextManager du printemps:
var manager = ObjectManager.GetNew<GraphicsContextManager>();
// manager IS a proxy and has the advice set!
var x = manager.DoSomeStuff();
// the DoSomeStuff Method is invoked, but my After advice is ignored
Les parties importantes du ObjectManager-je utiliser pour obtenir des objets du printemps:
static ObjectManager()
{
Context = ContextRegistry.GetContext();
}
public static T GetNew<T>()
{
return (T)Context.GetObject(typeof(T).FullName);
}
Spring ne fait pas exception, mais AfterAdvice est également ignoré. Des idées pourquoi? D'autres conseils que j'ai créés ont fonctionné sans aucun problème.
_____________ EDIT: ______________
J'ai ajouté une surcharge à mon ObjectManager:
public static T GetNew<T>(string typeFullName)
{
var ctx = GetContext();
return (T)ctx.GetObject(typeFullName);
}
Si j'utilise donc
var contextManager = ObjectManager.GetNew<IGraphicsContextManager>("GraphicsContextManager");
Jetant l'instance renvoyée par Spring non à son type concret mais plutôt à une interface, cela fonctionne comme prévu et mon conseil est utilisé (yay!).
Mais je ne comprends pas pourquoi?