Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Proposal extend existing DI framework to allow more than strings for keys #13094

Closed
mikehaas763 opened this issue Oct 14, 2015 · 1 comment
Closed

Comments

@mikehaas763
Copy link
Contributor

I think it would be useful today to be able to use more than just strings as keys in Angular.js's injector. I'm already aware that the DI framework written for Angular 2 has this capability.

Now that I've been writing all my app code in ES6 and TS I find myself wanting to use a reference to classes/functions like below.

// Module.js
import EmailDao from './EmailDao.js';
export default angular.module('org.name', [])
    .service(EmailDao, EmailDao); // Using a reference token here

// EmailList.js
import EmailDao from './EmailDao.js';

export default class EmailList {
    static get $inject() {
        return [EmailDao]; // Using a reference token here
    }

    constructor(emailDao) {
        this.emails = [];
        emailDao.getForPerson(123)
            .then(emails => this.emails = emails);
    }
}

In very large apps and very large organizations with a lot of shared modules you will often see hacking in a namespace in the string as a result of the key needing to be a string + there is essentially just one injector per ng1 app. For example .service('org.name.namespace.a', EmailDao). By extending the ng1 DI system to be keys by other tokens, we lose the need to use a string for an injector key and being that it's a reference to specific class/function it's guaranteed to be unique.

Thoughts?

@mikehaas763 mikehaas763 changed the title Proposal extending existing DI framework to allow more than strings for keys Proposal extend existing DI framework to allow more than strings for keys Oct 14, 2015
@Narretz
Copy link
Contributor

Narretz commented Oct 15, 2015

I think this is a duplicate of #10347

My guess is that it's quite complex to support this in 1.x. But if someone has a PR, we can definitely consider it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants