-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interception feature #86
Comments
👍 We need to do some thinking about it but sound like a good idea to me. |
Hi @ktutnik I'm doing some analysis on this week... can you please send me some documentation from an IoC where this is available? I would like to see theirs APIs and some real world use cases. Thanks 😄 |
Hi I've been reading about interception in Unity and Windsor Castle and I think what you are asking for in your example is not really interception as InversifyJS is not creating a proxy of the dependency being injected. If you could please let me know what do you have in mind about this feature I will be happy to see if I can implement it but I have another feature in mind (middleware) that could be what you are looking for and is more powerful. |
Yes interceptor is one step ahead. I saw the middleware feature of Inversify but I think it will be different. middleware seems a global way to change the behaviour of the Iversify system. but interception is specific to class that registered to the container. User freely intercept which class and define them in the registration. I made a dynamic proxy for this purposes. please take a look at https://github.com/ktutnik/benalu |
have a look at the test here https://github.com/ktutnik/benalu/blob/master/tests/benaluproxy.test.ts |
here is example what it will be: interface IKatana {
swing();
}
class Katana implement IKatana {
swing(){
console.log('Swing performed');
}
} registration: let kernel = new Kernel();
kernel.bin<IKatana>("IKatana").to(Katana).addInterception((invocation, context) => {
if(invocation.memberName == "swing"){
console.time();
invocation.proceed();
console.log("Katana.swing execution time");
console.timeEnd();
}
}); uses: var katana = kernel.get<IKatana>("IKatana");
katana.swing(); the result will be:
|
Hi @ktutnik thanks for your help :) I think I understand it now. I have a few things in mind. One of my main concerns is introducing dependencies. At the moment, we don't have dependencies (only polyfills for I can imagine something like the following working:
What are your thoughts? p.s. a good resource. |
I think Proxy is not clearly made for interception. The key point of interception is the execution step (befor execution, after execution or both). User even can choose to not to execute the original method at all. |
Please take a look to the following:
We can achieve the same but we will be using standards. |
Interception is now implemented in 2.0.0-alpha.3 but cannot be tested due to an issue with gulp-mocha and the --harmony-proxies flag. I'm going to create an issue for that issue, link it to to this and close this one. |
Was this work completed? I am on inversifyjs version 5.0.1 and do not see anything that seems to support this. EDIT: found it!: https://github.com/inversify/InversifyJS/blob/master/wiki/activation_handler.md |
I made an investigation and i think it can be implemented
I am thinking of the interceptor will be a simple callback that passed on registration. should be able to apply multiple interception (with fluent binding interface will implemented nicely):
invocation should consist of:
Proxy Class
to support those feature, it is required to create a proxy class on the fly. In javascript the process is real easy using
Object.getOwnPropertyDescriptor
andObject.create
The text was updated successfully, but these errors were encountered: