- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个 ASP.NET Core 2.1 应用程序。对于应用洞察遥测,我有自己的自定义类,但我也想使用内置的 ITelemetryInitializer
。启用自动交叉连接后,Simple Injector 会自动解决这些依赖关系吗?
更新
我尝试了下面的一段代码并得到了如下所示的错误。我不确定 Auto Crosswiring 还应该如何工作。
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IControllerActivator>(
new SimpleInjectorControllerActivator(container));
services.EnableSimpleInjectorCrossWiring(container);
services.UseSimpleInjectorAspNetRequestScoping(container);
container.AutoCrossWireAspNetComponents(app);
services.AddApplicationInsightsTelemetry(
applicationInsightsLoggerConfig.InstrumentationKey);
var test = Container.GetInstance<TelemetryConfiguration>();
The registered delegate for type TelemetryConfiguration threw an exception. The registered delegate for type IServiceScope threw an exception. The IServiceScope is registered as 'Async Scoped' lifestyle, but the instance is requested outside the context of an active (Async Scoped) scope.'
谢谢
最佳答案
此问题是由 a bug 引起的在 4.3.0 版的 ASP.NET Core Simple Injector 集成包中。
由于该错误,任何自动 交叉连接的依赖项都只能在事件作用域的上下文中得到解析,即使依赖项是Singleton
。 . TelemetryConfiguration
是 Singleton
.
当显式交叉连接该依赖项(即使用 container.CrossWire<TelemetryConfiguration>(app)
)时,问题就会消失,因为 CrossWire
允许 Singletons
在事件范围之外解决。
问题已在patch release 4.3.1中解决的集成包。在此版本中,您可以解决 TelemetryConfiguration
在事件网络请求或简单注入(inject)器的上下文之外 Scope
.
如果交叉线服务是 Transient
或 Scoped
,您仍然需要有一个事件的 Web 请求,或者,如果在后台线程上运行,则需要一个事件的简单注入(inject)器 Scope
.
关于c# - ASP.NET Core 中使用 UseApplicationInsights/AddApplicationInsights 的简单注入(inject)器用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51201919/
我正在构建一个 ASP.NET Core 2.1 应用程序。对于应用洞察遥测,我有自己的自定义类,但我也想使用内置的 ITelemetryInitializer。启用自动交叉连接后,Simple In
我是一名优秀的程序员,十分优秀!