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