Skip to content
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

How To: Inject 'cross-cutting' decorator to only a subset of implementations #1237

Open
patb23 opened this issue Aug 3, 2020 · 1 comment

Comments

@patb23
Copy link

patb23 commented Aug 3, 2020

Base Class:

@injectable()
export abstract class MWServiceClient implements ServiceClient{

introduced another abstract base class for adding 'caching' decorator:

@fluentProvide(TYPES.MWServiceClient).onActivation(((context: Context) => {
    console.log(`erl ${context} `); // want to introduce caching decorator
})).done()
// @injectable()
export abstract class CacheableServiceClient extends MWServiceClient implements ServiceClient {

In implementations where I want to cache, I am extending them to the 'Cacheable' base class.

@fluentProvide(TYPES.MWServiceClient).whenTargetTagged("party", true).done()
export class Portfolio extends CacheableServiceClient implements ServiceClient{

    constructor() {
        super(configOption);
    }

When I run the app, I notice that the constructor is called twice - one with 'configOption' and another with null/empty configOption. If I replace the 'fluentProvider' in CacheableServiceClient with 'injectable', the app starts up fine.

Could I get suggestions/references on how to selectivley apply cross-cutting decorators?

@patb23
Copy link
Author

patb23 commented Aug 3, 2020

if I add onActivation for Portfolio in my example above, it works - but wanted to specify at a common base class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant