问题描述
使用 Microsoft.Practices.Unity,为每个请求调用 Asp.Net webAPI 中 IDependencyResolver 的 GetService 方法,我可以在其中执行以下操作(容器的用户特定解析)
public UnityDependencyResolver(IUnityContainer container)
{
string userKey = GetUserFromContext();
if (_container != null)
{
if (_container.ContainsKey(userKey))
_container[userKey] = container;
else
_container.Add(userKey,container);
}
else
{
_container = new Dictionary<string,IUnityContainer>();
_container.Add(userKey,container);
}
}
公共对象GetService(Type serviceType) {
string userKey = GetUserKey();
return _container[userKey].Resolve(serviceType);
}
,我想在核心 API 中实现相同的目标。因为我需要它来显示特定于用户的容器数据。现在全球的两个用户可以看到彼此的数据
注意:不能使用 Core API 的默认 DI
请帮忙 谢谢
尝试了以下但没有运气 Custom unity Unity
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)