CDI using an interceptor for a decorator - decorator

I would like to know if it is possible by definition, that a decorator may have an interceptor for a method or not. I am using owb and it does not work!
EDIT: Just tested it with WELD and it's the same! Why does a decorator may not have an interceptor?

IMO: Methods in the decorator are never called directly through a contextual reference, therefore must not interceptable. These are container invocations of methods.

Related

How to provide capability like OnActivate (in Autofac) in Mvx.IoCProvider.Register

Autofac provides the OnActivated() method, which provides the capability to run any action after constructing a registered type.
Is possible to use a similar method in MvvmCross? Do you have any ideas to provide the same functionality?
It usually pays to understand the fundamentals of Dependency Injection (DI) instead of relying on particular DI Container features. Ask yourself the question: If I didn't have a DI Container, then how would I solve my problem?
Ironically, it turns out that things are usually much simpler with Pure DI.
If you didn't have a DI Container, then how would you run an action after construction of an object?
The easiest solution is to provide a factory that creates and initialises the object. Assuming the same API and requirements as the Autofac documentation implies, you could do this:
public static Dependency2 CreateDependency2(ITestOutputHelper output, Dependency1 dependency)
{
var d2 = new Dependency2(ITestOutputHelper output, Dependency1 dependency);
d2.Initialize();
return d2;
}
If you still must use another DI Container, most of them enable you to register a factory like the above against the type. I don't know how MvvmCross works, but I'd be surprised if this wasn't possible. If it isn't, you can implement an Adapter over your actual dependency. The Adapter would take care of running the action on the adapted object.
FWIW, if an object isn't in a valid state before you've run some action on it, then encapsulation is broken. The fundamental characteristic of encapsulation is that objects protect their invariants so that they can never be in invalid states. If possible, consider a better API design.

Show nested usages in IntelliJ IDEA

In IntelliJ IDEA, is there a way to see usages of a method nested in other usages?
I have a symfony2 app that has a class MyClass with method myMethod() this method is used in a bunch of services and controllers. I would like to trace all usages of this method all the way up to controllers that are linked to the app's routes. As a result, I would have a list of routes and corresponding controllers/methods that directly or indirectly use myMethod(). Is it possible?
In Java, it's Cmd-Alt-H (Ctrl-Alt-H on Windows), so I assume it's the same in PHP.
It's called "Call hierarchy". So you can use Cmd-shift-A (resp. Ctrl-shift-A and type "Call hierarchy" to find it.

how to spec createQueryBuilder() in controller

I'm writing phpspec test for controller
In action I am calling another method with this:
$this->getDoctrine()->getManager()->createQueryBuilder();
I cannot pass this in phpspec.
What I'm getting is
method Double\ObjectManager\P7::createQueryBuilder() is not defined
Have you got any suggestion how to spec it?
If you can't spec something, it's a indicator you have a bad design. In your case you should never create query builders in your controllers. Controller should be only a clue between different services.
For doctrine queries create repositories!

AS3/Flex Decorator Pattern

I'm trying to create a decorator class in AS3/Flex in order to add some functionality to a UI element. The problem is that I don't know how to automatically "redirect" method and property calls to the object being decorated. I suppose I'm looking for something like the __call() "magic method" from PHP, which is called every time the application calls a non-callable method.
So, the question is - how do I redirect calls for methods and properties (which aren't overriden/don't exist in the decorator class) to the object being decorated?
I think the closest to magic methods in actionscript would be extending Proxy.

Intercepting child method calls using Unity

Using PIAB / Unity, is it possible to intercept "child" method calls ?
e.g. the class has three methods ...
DoSomething(), DoFirst(), DoSecond()
The DoSomething() method calls DoFirst() which in turn calls DoSecond()
I can get interception of DoSomething, but I can't get anything for DoFirst and DoSecond. I've tried various of the Policy Injection rules ... Type Matching, Tag Attribute, Method Signature ... but nothing works. But I can intercept each method if I call them directly
So basic question ... can you even do this ?
And if so, how !!
I've found that I need to use the VirtualMethodInterceptor rather than the TransparentProxy or Interception interceptors

Resources