我有一个Net Core 2.1控制台应用程序,我在其中执行类似于以下操作的任务:
换句话说,我需要以某种方式在
class Program
{
static void Main(string[] args)
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false)
.Build();
var fullPath = configuration.GetValue<string>("tempPath:fullPath");
serviceCollection.AddTransient<MyService>();
serviceCollection.AddTransient<Worker>();
...
public class Worker
{
public string FullPath {get; set;}
private readonly MyService _myService;
public Worker(MyService myService,
string fullpath)
{
_myService = myService;
FullPath=fullpath;
}
换句话说,我需要以某种方式在
Worker
类中注入服务和配置字符串。有人能建议我正确的方法吗?