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


C# InstanceReference类代码示例

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


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


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