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

Proposal: Remove registration options entirely #23

Closed
dgeb opened this issue Feb 15, 2017 · 3 comments
Closed

Proposal: Remove registration options entirely #23

dgeb opened this issue Feb 15, 2017 · 3 comments

Comments

@dgeb
Copy link
Member

dgeb commented Feb 15, 2017

Currently there are two registration options:

export interface RegistrationOptions {
  singleton?: boolean;
  instantiate?: boolean;
}

If we move ahead with #21 then we can eliminate the instantiate option.

In order to remove the singleton option, we will require registration of factories that provide singleton construction behavior. In other words, Factory#create will need to return the same instance every time. This implies that factories can and should maintain state (frankly, the "can" part is a given with any create function).

@mixonic
Copy link
Member

mixonic commented Feb 15, 2017

eliminating instantiate seems only tied to allowing the factory and class to be registered separately, I think. singleton definitely requires #21 though.

Is there a proposal for register(specifier, klass, factory, options?)?

I'm in favor of this if we split class/factory and implement #21.

@dgeb
Copy link
Member Author

dgeb commented Feb 15, 2017

Is there a proposal for register(specifier, klass, factory, options?)?

I wanted to make this proposal first because removing options clears the way for:

register(specifier, class, creator = class, destructor?)

And a corresponding Factory interface:

interface Factory<T> {
  class: Constructor<T>;
  creator: Creator<T>;
  destructor?: Destructor<T>;
  
  // invokes `creator.create()` with registered injections
  create(injections?: Object): T;
}

Note: if we choose to separate class from creator, it will require further discussions and interface design.

@dgeb
Copy link
Member Author

dgeb commented Feb 17, 2017

I am backing out of this proposal on further consideration. Singletons must be per-container, not per-registry, so it is inappropriate to use a factory registered in a registry to maintain state per-container.

@dgeb dgeb closed this as completed Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants