惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
C
CERT Recently Published Vulnerability Notes
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
P
Privacy & Cybersecurity Law Blog
Simon Willison's Weblog
Simon Willison's Weblog
Jina AI
Jina AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
博客园_首页
F
Fortinet All Blogs
博客园 - Franky
Latest news
Latest news
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
D
Docker
Project Zero
Project Zero
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
Cisco Talos Blog
Cisco Talos Blog
Y
Y Combinator Blog
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Help Net Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
PCI Perspectives
PCI Perspectives
Cloudbric
Cloudbric
V
Visual Studio Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理

博客园 - LoveCoder

一个HTML小工具,可以显示你在网页上触摸点击的轨迹、位置、按压时长以及你触发的所有JS事件 SQL Server查询一个很大字段varchar字段的字符串被截断问题 sql server 每个表占用大小查询【转】 电商ERP系统源码出售 kubernetes镜像拉取失败解决方法 ErrImagePull 淘宝虚拟商品自动发货接口 如何排查线上w3wp.exe CPU高的问题,使用到了WinDbg、Visual studio来分析IIS进程池的.dmp文件 sql server 将数据库表里面的数据,转为insert语句,方便小批量转移数据 淘宝库存更新修改接口 淘宝开放平台上货接口,淘宝商品发布接口 C# 模拟http请求出现 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作[windows服务器] 淘宝订单信息获取接口API,淘宝打单发货接口 使用win-acme在windows+iis服务器下配置自动续期SSL证书【转】 开发Android应用程序,在Android10的系统上提示网络出错? android 反编译APK取源代码。 在.net core使用Serilog,只要简单的三步 淘宝订单信息获取接口API,淘宝打单发货接口 淘宝订单信息获取接口,淘宝订单信息获取API win10远程登录的账号密码
.net7(.net core) 依赖注入:从 AddSingleton 注册的类里面访问 AddScoped 的问题
LoveCoder · 2023-12-01 · via 博客园 - LoveCoder

记录一下以免忘记。

今天从NopCommerce开源项目里面把它的任务调度类拆出来到我的项目用的时候,发现报错,报错信息如下

Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: OUC.Services.ScheduleTasks.ITaskScheduler Lifetime: Singleton ImplementationType: OUC.Services.ScheduleTasks.TaskScheduler': Cannot consume scoped service 'OUC.Services.ScheduleTasks.IScheduleTaskService' from singleton 'OUC.Services.ScheduleTasks.ITaskScheduler'.)
---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: OUC.Services.ScheduleTasks.ITaskScheduler Lifetime: Singleton ImplementationType: OUC.Services.ScheduleTasks.TaskScheduler': Cannot consume scoped service 'OUC.Services.ScheduleTasks.IScheduleTaskService' from singleton 'OUC.Services.ScheduleTasks.ITaskScheduler'.
---> System.InvalidOperationException: Cannot consume scoped service 'OUC.Services.ScheduleTasks.IScheduleTaskService' from singleton 'OUC.Services.ScheduleTasks.ITaskScheduler'.

依赖注册的信息如下:

它在 TaskScheduler(单例注册)的构造函数中使用了 IScheduleTaskService ,而 IScheduleTaskService是用scoped注册的,我把这些代码拆到我的项目后,编译后运行竟然直接报错了,而它的却没有。

后来发现它默认用的是autofac,而我用的是.net core的依赖注入,然后github上有人对autofac这个bug进行了报告 https://github.com/autofac/Autofac.Extensions.DependencyInjection/issues/106

简单来说就是:autofac认为从单例的类访问scoped的类没问题,而.net core自带的依赖注入却不行

回到NopCommerce,它默认用的是autofac,而我项目没用,用的是.net core默认的。所以就报错了