Skip to content

Instantly share code, notes, and snippets.

@tpresthus
Created September 17, 2016 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpresthus/4854f319e91d72167dc8616e0b69de42 to your computer and use it in GitHub Desktop.
Save tpresthus/4854f319e91d72167dc8616e0b69de42 to your computer and use it in GitHub Desktop.
Example of IoC with ServiceLocator
class Autopilot
{
// Attempt to overtake the next car
// by signalling a turn, shifting to a lower gear
// and turning left (hoping that we're not in Britain)
public async void Overtake()
{
using(BlinkerService.Current.SignalLeft())
{
await ShifterService.Current.GearDown();
await SteeringService.Current.TurnLeft();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment