Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- namespace com.example.di
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Set up configuration sources.
- var builder = new ConfigurationBuilder()
- .SetBasePath(Path.Combine(Directory.GetCurrentDirectory()))
- .AddJsonFile("appsettings.json", optional: true);
- IConfiguration config = builder.Build();
- // Build service collection
- var serviceCollection = new ServiceCollection();
- // Add service to collection
- serviceCollection.AddScoped((sp) => config);
- // Build service provider
- var serviceProvider = serviceCollection.BuildServiceProvider();
- // Get service from provider
- serviceProvider.GetService<IConfiguration>()
- ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement