【发布时间】:2020-09-27 17:43:21
【问题描述】:
我正在尝试设置处理程序类的单例依赖注入。
此处理程序类在启动时从供应商处获取凭据,因此我需要对我的 ISomething 类的所有请求都应实际返回已启动的对象。
例如,在 .Net Core 中,您可以这样做:
x.Services.AddSingleton<ISomething, Something>(provider =>
{
var something= new Something()
something.credentials = "credentials"
return something;
}
);
如何在 .Net Framework 4.7.2 & Unity 中做到这一点?
谢谢。
【问题讨论】:
标签: c# .net dependency-injection unity-container