本文整理汇总了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 );
}
}
示例2: StrategyDoesNotAttemptToDisposeInstanceIfItIsNotDisposable
public void StrategyDoesNotAttemptToDisposeInstanceIfItIsNotDisposable()
{
var instance = new object();
var reference = new InstanceReference { Instance = instance };
strategy.Deactivate(contextMock.Object, reference);
}
示例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();
}
示例4: StrategyDoesNotAttemptToInitializeInstanceIfItIsNotInitializable
public void StrategyDoesNotAttemptToInitializeInstanceIfItIsNotInitializable()
{
var instance = new object();
var reference = new InstanceReference { Instance = instance };
strategy.Activate(contextMock.Object, reference);
}
示例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 );
}
示例6: StrategyStartsInstanceIfItIsStartable
public void StrategyStartsInstanceIfItIsStartable()
{
var instance = new StartableObject();
var reference = new InstanceReference { Instance = instance };
strategy.Activate(contextMock.Object, reference);
instance.WasStarted.Should().BeTrue();
}
示例7: StrategyInitializesInstanceIfItIsInitializable
public void StrategyInitializesInstanceIfItIsInitializable()
{
var instance = new InitializableObject();
var reference = new InstanceReference { Instance = instance };
strategy.Activate(contextMock.Object, reference);
instance.WasInitialized.ShouldBeTrue();
}
示例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));
}
}
示例9: StrategyDisposesInstanceIfItIsDisposable
public void StrategyDisposesInstanceIfItIsDisposable()
{
var instance = new NotifiesWhenDisposed();
var reference = new InstanceReference { Instance = instance };
strategy.Deactivate(contextMock.Object, reference);
instance.IsDisposed.ShouldBeTrue();
}
示例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());
}
}
示例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)));
}
示例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));
}
}
示例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 );
}
示例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));
}
}