Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. using Microsoft.Extensions.Configuration;
  2. using Microsoft.Extensions.DependencyInjection;
  3.  
  4. namespace com.example.di
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Set up configuration sources.
  11. var builder = new ConfigurationBuilder()
  12. .SetBasePath(Path.Combine(Directory.GetCurrentDirectory()))
  13. .AddJsonFile("appsettings.json", optional: true);
  14. IConfiguration config = builder.Build();
  15.  
  16. // Build service collection
  17. var serviceCollection = new ServiceCollection();
  18.  
  19. // Add service to collection
  20. serviceCollection.AddScoped((sp) => config);
  21.  
  22. // Build service provider
  23. var serviceProvider = serviceCollection.BuildServiceProvider();
  24.  
  25. // Get service from provider
  26. serviceProvider.GetService<IConfiguration>()
  27. ;
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement