本文整理汇总了C#中StructureMap.Pipeline.Instance.InstanceKey方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.InstanceKey方法的具体用法?C# Instance.InstanceKey怎么用?C# Instance.InstanceKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StructureMap.Pipeline.Instance
的用法示例。
在下文中一共展示了Instance.InstanceKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public object Get(Type pluginType, Instance instance, IBuildSession session)
{
object result = null;
int key = instance.InstanceKey(pluginType);
_lock.EnterUpgradeableReadLock();
if (_objects.ContainsKey(key))
{
result = _objects[key];
_lock.ExitUpgradeableReadLock();
}
else
{
_lock.EnterWriteLock();
try
{
result = buildWithSession(pluginType, instance, session);
_objects.Add(key, result);
}
finally
{
_lock.ExitWriteLock();
}
}
return result;
}
示例2: Has
public bool Has(Type pluginType, Instance instance)
{
return _lock.Read(() => {
var key = instance.InstanceKey(pluginType);
return _objects.ContainsKey(key);
});
}
示例3: Eject
public void Eject(Type pluginType, Instance instance)
{
int key = instance.InstanceKey(pluginType);
_lock.MaybeWrite(() => {
if (!_objects.ContainsKey(key)) return;
_lock.Write(() => {
var disposable = _objects[key] as IDisposable;
_objects.Remove(key);
disposable.SafeDispose();
});
});
}
示例4: Eject
public void Eject(Type pluginType, Instance instance)
{
// Prevent null reference exception.
if (pluginType.AssemblyQualifiedName == null)
return;
var key = instance.InstanceKey(pluginType);
_lock.MaybeWrite(() => {
if (!_objects.ContainsKey(key)) return;
_lock.Write(() => {
var disposable = _objects[key] as IDisposable;
_objects.Remove(key);
disposable.SafeDispose();
});
});
}
示例5: Get
public object Get(Type pluginType, Instance instance, IBuildSession session)
{
object result;
var key = instance.InstanceKey(pluginType);
_lock.EnterUpgradeableReadLock();
try
{
if (_instances.Contains(instance))
{
throw new StructureMapBuildException("Bi-directional dependency relationship detected!" +
Environment.NewLine + "Check the StructureMap stacktrace below:");
}
if (_objects.ContainsKey(key))
{
result = _objects[key];
}
else
{
_lock.EnterWriteLock();
try
{
_instances.Add(instance);
result = buildWithSession(pluginType, instance, session);
_objects.Add(key, result);
}
finally
{
_instances.Remove(instance);
_lock.ExitWriteLock();
}
}
}
finally
{
_lock.ExitUpgradeableReadLock();
}
return result;
}
示例6: Set
public void Set(Type pluginType, Instance instance, object value)
{
if (value == null) return;
_lock.Write(() => {
int key = instance.InstanceKey(pluginType);
if (_objects.ContainsKey(key))
{
_objects[key] = value;
}
else
{
_objects.Add(key, value);
}
});
}