Guest User

Untitled

a guest
Jun 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. var serviceCollection = new ServiceCollection();
  6.  
  7. serviceCollection.AddTransient<SomeDependency>();
  8. serviceCollection.AddScoped<SomeManager>();
  9. serviceCollection.AddScoped<SomeManager>();
  10.  
  11. var serviceProvider = serviceCollection.BuildServiceProvider();
  12.  
  13. var service = serviceProvider.GetServices<SomeManager>();
  14.  
  15. Console.WriteLine("Hello World!");
  16. }
  17. }
  18.  
  19. public class SomeManager
  20. {
  21. private SomeDependency _dependency;
  22.  
  23. public SomeManager(SomeDependency dependency)
  24. {
  25. _dependency = dependency;
  26. }
  27. }
  28.  
  29. public class SomeDependency
  30. {
  31. public int MyProperty { get; set; }
  32. }
Add Comment
Please, Sign In to add comment