Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

[WIP] docs: add DI cookbook #1012

Closed
wants to merge 2 commits into from
Closed

Conversation

thelgevold
Copy link
Contributor

ATTENTION: this PR closed (see last comment); continued as PR #1022

@wardbell Adding the DI cookbook. Let me know if this is what you had in mind.

Adding @PascalPrecht as well in case he has time to offer some feedback.

working on text

text

working on bios

more text

added plunker

added sorted list

text

formatting

hero of the month

use labels

hero of the month

formatting

text

fixed text

added host optional

formating

text

element-ref

text updates

text updates

images

fixed image

added test

text
@Foxandxss
Copy link
Member

We are promoting @Injectable() in every service (even if it has no dependency) as the best practice.

@thelgevold
Copy link
Contributor Author

Thanks for pointing that out @Foxandxss - I will update if that's the direction we are going in.

That said, I am not sure I love that requirement. Mainly because it adds a dependency on Angular 2 where it isn't needed.

@thelgevold
Copy link
Contributor Author

Based on team feedback I have added Injectable to all services for consistency

@wardbell
Copy link
Contributor

Hi Tor -
I'm documenting here some of the more important changes that I'm making/recommending.

  1. We recommend registering application-wide providers in the root component, not in bootstrapping. Anything that really belongs with the app itself goes in AppComponent. I'm moving your app-specific providers there. Illustrated usage by extending HeroBiosComponent with logger service injection.
  2. We only register Angular overrides in the bootstrapper. A good example is router LocationStrategy or a dev-time http backend fake like a2-in-memory-web-api.
  3. All component class names should end in Component. Fixed that.
  4. We recommend that constructors be super simple and never call services that could do anything like hit a database. I revised the SortedHeroesComponent by moving the HeroesService call to ngOnInit.
  5. I wanted to make a more dramatic argument against component inheritance so I made HeroesBase into a component. I also shifted the sorting logic to SortedHeroesComponent for ... ahem ... greater realism.
  6. I think the inheritance issues are lower priority than anything else that you're showing. I shifted it to the bottom.

I'll update this comment as I make more changes.

@wardbell wardbell changed the title docs:Creating DI cookbook [WIP] docs:Creating DI cookbook Mar 30, 2016
@wardbell wardbell changed the title [WIP] docs:Creating DI cookbook [WIP] docs: add DI cookbook Mar 30, 2016
@wardbell
Copy link
Contributor

Hey Tor - I've made more changes but it's in a broken state. Please don't touch at the moment.

@wardbell wardbell closed this Mar 30, 2016
@wardbell wardbell deleted the cb-di-TOR branch March 30, 2016 15:53
@wardbell
Copy link
Contributor

AARGH. I renamed the branch to all lowercase (our standard), and it closed this PR.

Please see continuation PR #1022

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

Successfully merging this pull request may close these issues.

4 participants