当前位置: 首页>>代码示例>>C#>>正文


C# IContext.GetScope方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:LuckyStarry,项目名称:Ninject,代码行数:26,代码来源:Cache.cs

示例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;
            }
        }
开发者ID:bbawol,项目名称:ninject,代码行数:41,代码来源:Cache.cs

示例3: CacheEntry

 public CacheEntry(IContext context, InstanceReference reference)
 {
     Context = context;
     Reference = reference;
     Scope = new WeakReference(context.GetScope());
 }
开发者ID:developingchris,项目名称:ninject,代码行数:6,代码来源:Cache.cs

示例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;
            }
        }
开发者ID:developingchris,项目名称:ninject,代码行数:33,代码来源:Cache.cs

示例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);
        }
开发者ID:developingchris,项目名称:ninject,代码行数:21,代码来源:Cache.cs

示例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;
        }
开发者ID:ninject,项目名称:Ninject,代码行数:22,代码来源:Context.cs

示例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);
            }
        }
开发者ID:Haacked,项目名称:ninject,代码行数:24,代码来源:Cache.cs

示例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);
        }
开发者ID:Haacked,项目名称:ninject,代码行数:38,代码来源:Cache.cs

示例9: CacheEntry

 public CacheEntry(IContext context)
 {
     Context = context;
     Scope = new WeakReference(context.GetScope());
 }
开发者ID:schambers,项目名称:ninject,代码行数:5,代码来源:Cache.cs

示例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);
            }
        }
开发者ID:schambers,项目名称:ninject,代码行数:19,代码来源:Cache.cs


注:本文中的IContext.GetScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。