How to use Dependency Injection in .Net core Console Application
问题 I have to add data to my database using a Console Application. In the Main() method I added: var services = new ServiceCollection(); var serviceProvider = services.BuildServiceProvider(); var connection = @"Server = (localdb)\mssqllocaldb; Database = CryptoCurrency; Trusted_Connection = True; ConnectRetryCount = 0"; services.AddDbContext<CurrencyDbContext>(options => options.UseSqlServer(connection)); In another class I add functionality to work with database, and made it like a Web Api