question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce an interception mechanism

See original GitHub issue

It would be nice to have an interception mechanism similar to the $http interception from angular.js, but based on any services working together with the injection api. This would allow to introduce service behaviors based on aspect oriented programming, for example authorization, exception handling, logging etc.

As a reference I would like to mention the Unity dependency injection framework for .Net: https://msdn.microsoft.com/en-us/library/dn178466(v=pandp.30).aspx

I could imagine that working with interceptors looks like following snippets:

Interceptor implementation

class MyInterceptionBehavior implements InterceptionBehavior {
    intercept(input:FunctionInvocation, getNext:GetNextCallback) : FunctionReturn {
        let result: FunctionReturn;

        // do something before calling the next interceptor or the final implementation

        result = getNext()(input, getNext);

        // do something after calling the next interceptor or the final implementation

        return result;
    }
}

Interceptor registration based in decorators

@Intercept({
    behavior: MyInterceptionBehavior,
    order: 1
})
class MyService {
    @Intercept({
        behavior: MyInterceptionBehavior,
        order: 2
    })
    doSomething(): void {
    }
}

And also manual interceptor registration for types which are out of my control, e.g. Router or Http

bind(MyService).toFactory(() => ....).interceptWith(MyInterceptor)

The interception API from Unity has one drawback. It does not support interface interception without a target implementation. But this would also be nice to have. Imagine I have several service interface where I can provide a generic implementation without to be forced implementing every single interface in the same way. An example usage could be a service proxy. May be this could look like following:

bind(MyService).toInterceptor(MyInterfaceInterceptor)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
lehmamiccommented, Jul 29, 2015

@jeffbcross I would rather compare it to the connect module of Node JS than with the provider of $http interceptors API in Angular 1.

The interceptor API i’m proposing would create a proxy around the service. The proxy has a pipeline of interceptors (similar to the middleware pipeline in Connect) which gets executed during every method and property call of the service. By calling result = getNext()(input, getNext); the interceptor will invoke the next interceptor in the pipeline or, in case it is the last interceptor, the original service function. Interceptor Pipeline

An interceptor would not get fix defined parameter like req, resp or $http, but the metadata of the called service and method. This would include information about the parameter types, values return types, values etc. I called this FunctionInvocation in my sample above.

This would allow us, to attach behaviors (which have to be written only once) to any service (not only $http), which is very powerful. I consider this as very valuable for large enterprise applications.

1reaction
mheverycommented, Jul 1, 2016

This is obsolete, and no longer relevant / actionable. To keep our issues clean, we are aggressively closing them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Direct Interception - an overview | ScienceDirect Topics
Direct interception is equally effective in liquids and gases and is the predominant mechanism for removing particles from liquids. In the depth of...
Read more >
Lawful interception - Wikipedia
Lawful interception (LI) refers to the facilities in telecommunications and telephone networks that allow law enforcement agencies with court orders or ...
Read more >
Filtration Mechanisms of Particulate Respirators
Respirable particles are filtered using which mechanisms. (select one):. A. Impaction. B. Interception. C. Diffusion. D. All of the above.
Read more >
Interception Characteristics and Pollution Mechanism of the ...
1. Introduction. Polymer flooding is the leading technology for tertiary oil recovery in oil fields. This technology benefits the oil well and increases ......
Read more >
Filtration Mechanism of Fine Particle - PMC - NCBI
3.7, r 1 ≤ r f + r p), particles will be intercepted and then deposited on the fiber surface, which is called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found