本文整理汇总了C#中IContext.GetScope方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.GetScope方法的具体用法?C# IContext.GetScope怎么用?C# IContext.GetScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.GetScope方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remember
/// <summary>
/// Stores the specified context in the cache.
/// </summary>
/// <param name="context">The context to store.</param>
/// <param name="reference">The instance reference.</param>
public void Remember(IContext context, InstanceReference reference)
{
var scope = context.GetScope();
var entry = new CacheEntry(context, reference);
lock (this.entries)
{
var weakScopeReference = new ReferenceEqualWeakReference(scope);
if (!this.entries.ContainsKey(weakScopeReference))
{
this.entries[weakScopeReference] = new Multimap<IBindingConfiguration, CacheEntry>();
var notifyScope = scope as INotifyWhenDisposed;
if (notifyScope != null)
{
notifyScope.Disposed += (o, e) => this.Clear(weakScopeReference);
}
}
this.entries[weakScopeReference].Add(context.Binding.BindingConfiguration, entry);
}
}
示例2: TryGet
/// <summary>
/// Tries to retrieve an instance to re-use in the specified context.
/// </summary>
/// <param name="context">The context that is being activated.</param>
/// <returns>The instance for re-use, or <see langword="null"/> if none has been stored.</returns>
public object TryGet(IContext context)
{
Ensure.ArgumentNotNull(context, "context");
var scope = context.GetScope();
if (scope == null)
{
return null;
}
lock (this.entries)
{
Multimap<IBindingConfiguration, CacheEntry> bindings;
if (!this.entries.TryGetValue(scope, out bindings))
{
return null;
}
foreach (var entry in bindings[context.Binding.BindingConfiguration])
{
if (context.HasInferredGenericArguments)
{
var cachedArguments = entry.Context.GenericArguments;
var arguments = context.GenericArguments;
if (!cachedArguments.SequenceEqual(arguments))
{
continue;
}
}
return entry.Reference.Instance;
}
return null;
}
}
示例3: CacheEntry
public CacheEntry(IContext context, InstanceReference reference)
{
Context = context;
Reference = reference;
Scope = new WeakReference(context.GetScope());
}
示例4: TryGet
/// <summary>
/// Tries to retrieve an instance to re-use in the specified context.
/// </summary>
/// <param name="context">The context that is being activated.</param>
/// <returns>The instance for re-use, or <see langword="null"/> if none has been stored.</returns>
public object TryGet(IContext context)
{
Ensure.ArgumentNotNull(context, "context");
lock (_entries)
{
var scope = context.GetScope();
foreach (CacheEntry entry in _entries[context.Binding])
{
if (!ReferenceEquals(entry.Scope.Target, scope))
continue;
if (context.HasInferredGenericArguments)
{
var cachedArguments = entry.Context.GenericArguments;
var arguments = context.GenericArguments;
if (!cachedArguments.SequenceEqual(arguments))
continue;
}
return entry.Reference.Instance;
}
return null;
}
}
示例5: Remember
/// <summary>
/// Stores the specified context in the cache.
/// </summary>
/// <param name="context">The context to store.</param>
/// <param name="reference">The instance reference.</param>
public void Remember(IContext context, InstanceReference reference)
{
Ensure.ArgumentNotNull(context, "context");
var entry = new CacheEntry(context, reference);
lock (_entries)
{
_entries[context.Binding].Add(entry);
}
var notifyScope = context.GetScope() as INotifyWhenDisposed;
if (notifyScope != null)
notifyScope.Disposed += (o, e) => Forget(entry);
}
示例6: IsCyclical
private bool IsCyclical(IContext targetContext)
{
if (targetContext == null)
{
return false;
}
if (targetContext.Request.Service == this.Request.Service)
{
if (!(this.Request.Target is PropertyTarget) || targetContext.GetScope() != this.GetScope() || this.GetScope() == null)
{
return true;
}
}
if (this.IsCyclical(targetContext.Request.ParentContext))
{
return true;
}
return false;
}
示例7: TryGet
/// <summary>
/// Tries to retrieve an instance to re-use in the specified context.
/// </summary>
/// <param name="context">The context that is being activated.</param>
/// <returns>The instance for re-use, or <see langword="null"/> if none has been stored.</returns>
public object TryGet(IContext context)
{
Ensure.ArgumentNotNull(context, "context");
var scope = context.GetScope();
#if !NO_WEB
var httpScope = scope as HttpContext;
if(httpScope != null)
{
var entries = GetEntriesCache(httpScope);
return GetItemFromCache(context, httpScope, entries);
}
#endif
lock (_entries)
{
return GetItemFromCache(context, scope, _entries);
}
}
示例8: Remember
/// <summary>
/// Stores the specified context in the cache.
/// </summary>
/// <param name="context">The context to store.</param>
/// <param name="reference">The instance reference.</param>
public void Remember(IContext context, InstanceReference reference)
{
Ensure.ArgumentNotNull(context, "context");
var entry = new CacheEntry(context, reference);
#if !NO_WEB
var httpScope = context.GetScope() as HttpContext;
if(httpScope != null)
{
var entries = GetEntriesCache(httpScope);
entries[context.Binding].Add(entry);
var disposable = reference.Instance as IDisposable;
if(disposable != null)
{
var disposables = GetRequestScopedDisposables(httpScope);
disposables.Add(disposable);
}
return;
}
#endif
lock (_entries)
{
_entries[context.Binding].Add(entry);
}
var notifyScope = context.GetScope() as INotifyWhenDisposed;
if (notifyScope != null)
notifyScope.Disposed += (o, e) => Forget(entry);
}
示例9: CacheEntry
public CacheEntry(IContext context)
{
Context = context;
Scope = new WeakReference(context.GetScope());
}
示例10: Remember
/// <summary>
/// Stores the specified context in the cache.
/// </summary>
/// <param name="context">The context to store.</param>
public void Remember(IContext context)
{
Ensure.ArgumentNotNull(context, "context");
lock (_entries)
{
var entry = new CacheEntry(context);
_entries[context.Binding].Add(entry);
var scope = context.GetScope() as INotifyWhenDisposed;
if (scope != null)
scope.Disposed += (o, e) => Forget(entry);
}
}