中間件中如果想用Service服務,不能用注入,需要這樣寫:
using (var serviceCope = httpContext.RequestServices.CreateScope()) { ISysSettingService? _sysSettingService = serviceCope.ServiceProvider.GetService<ISysSettingService>(); if (_sysSettingService != null){...} }
來源:https://www.cnblogs.com/shipengfei/p/16092063.html