示例#1
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureServices((hostContext, services) =>
 {
     services.AddScoped <IAppleItem>((_) =>
     {
         var apple = new WorkerItem {
             Name = "Apple"
         };
         return(Proxy.CreateInstance <IAppleItem, WorkerItem>(apple));
     });
     services.AddScoped <IPearItem>((_) =>
     {
         var pear = new WorkerItem {
             Name = "Pear"
         };
         return(Proxy.CreateInstance <IPearItem, WorkerItem>(pear));
     });
     services.AddScoped <WorkerService>();
     services.AddHostedService <Worker>();
 });
 public WorkerService(IPearItem pear, IAppleItem apple, ILogger <Worker> logger)
 {
     _pear   = pear.Value;
     _apple  = apple.Value;
     _logger = logger;
 }