Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #!/bin/python
  2. '''
  3. This example is used in README.rst as the first introduction to Fang.
  4. '''
  5.  
  6. import fang
  7.  
  8. di = fang.Di(namespace='.com.example.myproject')
  9.  
  10. @di.dependsOn('multiplier')
  11. def multiply(n):
  12.     '''Multiply the given number n by some configured multiplier.'''
  13.     multiplier = di.resolver.unpack(multiply)
  14.     return multiplier(2) * n
  15.  
  16. providers = fang.ResourceProviderRegister(namespace='.com.example.myproject')
  17.  
  18. @providers.register('multiplier')
  19. def give_multiplier(number):
  20.     '''Give a multiplier of 2.'''
  21.     return number
  22.  
  23. def main():
  24.     # Here at our program entry-point, we configure what set of providers
  25.     # will be used to meet our dependencies
  26.     di.providers.load(providers)
  27.     # Prints 10
  28.     print(multiply(5))
  29.  
  30. if __name__ == '__main__':
  31.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement