• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# InstanceReference类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中InstanceReference的典型用法代码示例。如果您正苦于以下问题:C# InstanceReference类的具体用法?C# InstanceReference怎么用?C# InstanceReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InstanceReference类属于命名空间,在下文中一共展示了InstanceReference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Activate

        public override void Activate( IContext context, InstanceReference reference )
        {
            var messageBroker = context.Kernel.Components.Get<IMessageBroker>();

            List<PublicationDirective> publications = context.Plan.GetAll<PublicationDirective>().ToList();

            // I don't think this is needed in Ninject2
            //if (publications.Count > 0)
            //   context.ShouldTrackInstance = true;

            foreach ( PublicationDirective publication in publications )
            {
                IMessageChannel channel = messageBroker.GetChannel( publication.Channel );
                channel.AddPublication( reference.Instance, publication.Event );
            }

            List<SubscriptionDirective> subscriptions = context.Plan.GetAll<SubscriptionDirective>().ToList();

            // I don't think this is needed in Ninject2
            //if (subscriptions.Count > 0)
            //    context.ShouldTrackInstance = true;

            foreach ( SubscriptionDirective subscription in subscriptions )
            {
                IMessageChannel channel = messageBroker.GetChannel( subscription.Channel );
                channel.AddSubscription( reference.Instance, subscription.Injector, subscription.Thread );
            }
        }
开发者ID:MiguelMadero,项目名称:ninject.extensions.messagebroker,代码行数:28,代码来源:EventBindingStrategy.cs


示例2: StrategyDoesNotAttemptToDisposeInstanceIfItIsNotDisposable

        public void StrategyDoesNotAttemptToDisposeInstanceIfItIsNotDisposable()
        {
            var instance = new object();
            var reference = new InstanceReference { Instance = instance };

            strategy.Deactivate(contextMock.Object, reference);
        }
开发者ID:brunomlopes,项目名称:ninject,代码行数:7,代码来源:DisposableStrategyTests.cs


示例3: InstanceIsRemovedFromCache

        public void InstanceIsRemovedFromCache()
        {
            var scope = new object();
            var sword = new Sword();
            var reference = new InstanceReference { Instance = sword };

            var writeContext = new Mock<IContext>();
            writeContext.SetupGet(x => x.Binding).Returns(bindingMock.Object);
            writeContext.SetupGet(x => x.HasInferredGenericArguments).Returns(true);
            writeContext.SetupGet(x => x.GenericArguments).Returns(new[] { typeof(int) });
            writeContext.Setup(x => x.GetScope()).Returns(scope);

            cache.Remember(writeContext.Object, reference);

            var readContext = new Mock<IContext>();
            readContext.SetupGet(x => x.Binding).Returns(bindingMock.Object);
            readContext.SetupGet(x => x.HasInferredGenericArguments).Returns(true);
            readContext.SetupGet(x => x.GenericArguments).Returns(new[] { typeof(int) });
            readContext.Setup(x => x.GetScope()).Returns(scope);

            object instance1 = cache.TryGet(readContext.Object);
            instance1.ShouldBeSameAs(reference.Instance);

            bool result = cache.Release(instance1);
            result.ShouldBeTrue();

            object instance2 = cache.TryGet(readContext.Object);
            instance2.ShouldBeNull();
        }
开发者ID:shijucv,项目名称:ninject,代码行数:29,代码来源:CacheTests.cs


示例4: StrategyDoesNotAttemptToInitializeInstanceIfItIsNotInitializable

        public void StrategyDoesNotAttemptToInitializeInstanceIfItIsNotInitializable()
        {
            var instance = new object();
            var reference = new InstanceReference { Instance = instance };

            strategy.Activate(contextMock.Object, reference);
        }
开发者ID:brunomlopes,项目名称:ninject,代码行数:7,代码来源:InitializableStrategyTests.cs


示例5: Activate

 /// <summary>
 /// Activates the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="reference">The reference.</param>
 public override void Activate( IContext context, InstanceReference reference )
 {
     if ( ShouldProxy( context ) )
     {
         context.Kernel.Components.Get<IProxyFactory>().Wrap( context, reference );
     }
     base.Activate( context, reference );
 }
开发者ID:hereyes,项目名称:ninject.extensions.interception,代码行数:13,代码来源:ProxyActivationStrategy.cs


示例6: StrategyStartsInstanceIfItIsStartable

        public void StrategyStartsInstanceIfItIsStartable()
        {
            var instance = new StartableObject();
            var reference = new InstanceReference { Instance = instance };

            strategy.Activate(contextMock.Object, reference);
            instance.WasStarted.Should().BeTrue();
        }
开发者ID:LuckyStarry,项目名称:Ninject,代码行数:8,代码来源:StartableStrategyTests.cs


示例7: StrategyInitializesInstanceIfItIsInitializable

        public void StrategyInitializesInstanceIfItIsInitializable()
        {
            var instance = new InitializableObject();
            var reference = new InstanceReference { Instance = instance };

            strategy.Activate(contextMock.Object, reference);
            instance.WasInitialized.ShouldBeTrue();
        }
开发者ID:brunomlopes,项目名称:ninject,代码行数:8,代码来源:InitializableStrategyTests.cs


示例8: Deactivate

 /// <summary>
 /// Deactivates the instance in the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="reference">The instance reference.</param>
 public void Deactivate(IContext context, InstanceReference reference)
 {
     Ensure.ArgumentNotNull(context, "context");
     if (!this.activationCache.IsDeactivated(reference.Instance))
     {
         this.Strategies.Map(s => s.Deactivate(context, reference));
     }
 }
开发者ID:bbawol,项目名称:ninject,代码行数:13,代码来源:Pipeline.cs


示例9: StrategyDisposesInstanceIfItIsDisposable

        public void StrategyDisposesInstanceIfItIsDisposable()
        {
            var instance = new NotifiesWhenDisposed();
            var reference = new InstanceReference { Instance = instance };

            strategy.Deactivate(contextMock.Object, reference);
            instance.IsDisposed.ShouldBeTrue();
        }
开发者ID:brunomlopes,项目名称:ninject,代码行数:8,代码来源:DisposableStrategyTests.cs


示例10: Activate

 /// <summary>
 /// Injects values into the properties as described by <see cref="MethodInjectionDirective"/>s
 /// contained in the plan.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="reference">A reference to the instance being activated.</param>
 public override void Activate(IContext context, InstanceReference reference)
 {
     foreach (var directive in context.Plan.GetAll<MethodInjectionDirective>())
     {
         var arguments = directive.Targets.Select(target => target.ResolveWithin(context));
         directive.Injector(reference.Instance, arguments.ToArray());
     }
 }
开发者ID:ninject,项目名称:Ninject,代码行数:14,代码来源:MethodInjectionStrategy.cs


示例11: CallsDeactivateOnStrategies

        public void CallsDeactivateOnStrategies()
        {
            var contextMock = new Mock<IContext>();
            var reference = new InstanceReference();

            this.Pipeline.Deactivate(contextMock.Object, reference);

            this.StrategyMocks.Map(mock => mock.Verify(x => x.Deactivate(contextMock.Object, reference)));
        }
开发者ID:Qiredev,项目名称:ninject,代码行数:9,代码来源:PipelineTests.cs


示例12: Deactivate

        /// <summary>
        /// Contributes to the deactivation of the instance in the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">A reference to the instance being deactivated.</param>
        public override void Deactivate(IContext context, InstanceReference reference)
        {
            base.Deactivate(context, reference);

            if (this.Log != null)
            {
                this.Log.Info("Ninject binding deactivated: " + context.Binding.Service + " => " + reference.Instance.GetType());
            }
        }
开发者ID:azzlack,项目名称:Ninject.Extensions.BindingActivationLogger,代码行数:14,代码来源:BindingActivationLogger.cs


示例13: Activate

 public void Activate(IContext context, InstanceReference reference)
 {
     Type instanceType = reference.Instance.GetType();
     LOGGER.Info("Component activation: " + instanceType.Name);
     if (!instanceType.IsAssignableFrom(typeof(Splashscreen))) {
         Splashscreen splashscreen = App.Kernel.Get<Splashscreen>();
         splashscreen.SetProgress(string.Format("{0} loading...", instanceType.Name));
     }
 }
开发者ID:GoldRenard,项目名称:DMOAdvancedLauncher,代码行数:9,代码来源:ActivationStrategy.cs


示例14: Activate

        /// <summary>
        /// Activates the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">The reference.</param>
        public override void Activate( IContext context, InstanceReference reference )
        {
            if ( ShouldProxy( context ) )
            {
                this.proxyFactory.Wrap( context, reference );
            }

            base.Activate( context, reference );
        }
开发者ID:njmube,项目名称:Ninject.Extensions.Interception,代码行数:14,代码来源:ProxyActivationStrategy.cs


示例15: Activate

        /// <summary>
        /// Activates the instance in the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">The instance reference.</param>
        public void Activate(IContext context, InstanceReference reference)
        {
            Contract.Requires(context != null);
            Contract.Requires(reference != null);

            if (!this.activationCache.IsActivated(reference.Instance))
            {
                this.Strategies.Map(s => s.Activate(context, reference));
            }
        }
开发者ID:ninject,项目名称:Ninject,代码行数:15,代码来源:Pipeline.cs


示例16: WhenAlreadyActiavatedNothingHappens

        public void WhenAlreadyActiavatedNothingHappens()
        {
            var contextMock = new Mock<IContext>();
            var reference = new InstanceReference();
            this.ActivationCacheMock.Setup(activationCache => activationCache.IsActivated(It.IsAny<object>())).Returns(true);

            this.Pipeline.Activate(contextMock.Object, reference);

            this.StrategyMocks.Map(mock => mock.Verify(x => x.Activate(contextMock.Object, reference), Times.Never()));
        }
开发者ID:Qiredev,项目名称:ninject,代码行数:10,代码来源:PipelineTests.cs


示例17: Activate

 /// <summary>
 /// Activates the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="reference">The reference.</param>
 public override void Activate(IContext context, InstanceReference reference)
 {
     var namedScopeParameters = context.Parameters.OfType<NamedScopeParameter>();
     foreach (var namedScopeParameter in namedScopeParameters)
     {
         context.Kernel.Get<NamedScopeReference>(
             new NamedScopeReferenceScopeParameter(reference.Instance),
             new ConstructorArgument("scope", namedScopeParameter.Scope));
     }
 }
开发者ID:ninject,项目名称:Ninject.Extensions.NamedScope,代码行数:15,代码来源:NamedScopeActivationStrategy.cs


示例18: Wrap

        /// <summary>
        /// Wraps the instance in the specified context in a proxy.
        /// </summary>
        /// <param name="context">The context in which the instance was activated.</param>
        /// <param name="reference">The <see cref="InstanceReference"/> to wrap.</param>
        public override void Wrap( IContext context, InstanceReference reference )
        {
            var wrapper = new LinFuWrapper( Kernel, context, reference.Instance );

            Type targetType = context.Request.Service;

            reference.Instance = targetType.IsInterface 
                ? this._factory.CreateProxy(typeof(object), wrapper, context.Request.Service) 
                : this._factory.CreateProxy(context.Request.Service, wrapper);
        }
开发者ID:Ning-Sun,项目名称:ninject.extensions.interception,代码行数:15,代码来源:LinFuProxyFactory.cs


示例19: Activate

        /// <summary>
        /// Injects values into the properties as described by <see cref="PropertyInjectionDirective"/>s
        /// contained in the plan.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">A reference to the instance being activated.</param>
        public override void Activate(IContext context, InstanceReference reference)
        {
            Ensure.ArgumentNotNull(context, "context");
            Ensure.ArgumentNotNull(reference, "reference");

            foreach (var directive in context.Plan.GetAll<PropertyInjectionDirective>())
            {
                object value = GetValue(context, directive.Target);
                directive.Injector(reference.Instance, value);
            }
        }
开发者ID:JasonTrue,项目名称:ninject,代码行数:17,代码来源:PropertyInjectionStrategy.cs


示例20: ReturnsNullIfScopeIsNull

        public void ReturnsNullIfScopeIsNull()
        {
            var reference = new InstanceReference { Instance = new Sword() };
            var context1 = CreateContext(new TestObject(42), this.bindingConfiguration);
            var context2 = CreateContext(null, this.bindingConfiguration);

            cache.Remember(context1, reference);
            object instance = cache.TryGet(context2);

            instance.Should().BeNull();
        }
开发者ID:LuckyStarry,项目名称:Ninject,代码行数:11,代码来源:CacheTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Instant类代码示例发布时间:2022-05-24
下一篇:
C# InstanceProducer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap