本文整理汇总了C#中InstanceReference.IfInstanceIs方法的典型用法代码示例。如果您正苦于以下问题:C# InstanceReference.IfInstanceIs方法的具体用法?C# InstanceReference.IfInstanceIs怎么用?C# InstanceReference.IfInstanceIs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InstanceReference
的用法示例。
在下文中一共展示了InstanceReference.IfInstanceIs方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deactivate
/// <summary>
/// Disposes the specified instance.
/// </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)
{
reference.IfInstanceIs<ICommunicationObject>(x =>
{
if (x.State == CommunicationState.Faulted)
{
x.Abort();
}
else
{
try
{
x.Close();
}
catch
{
x.Abort();
}
}
});
base.Deactivate(context, reference);
}
示例2: Activate
/// <summary>
/// Initializes the specified instance.
/// </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)
{
reference.IfInstanceIs<IInitializable>(x => x.Initialize());
}
示例3: Deactivate
/// <summary>
/// Disposes the specified instance.
/// </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)
{
reference.IfInstanceIs<IDisposable>(x => x.Dispose());
}
示例4: Deactivate
/// <summary>
/// Stops the specified instance.
/// </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)
{
reference.IfInstanceIs<IStartable>(x => x.Stop());
}
示例5: Deactivate
/// <summary>
/// Disposes the specified instance.
/// </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)
{
reference.IfInstanceIs<ICommunicationObject>(x => x.CloseOrAbort());
base.Deactivate(context, reference);
}
示例6: Deactivate
public void Deactivate(IContext context, InstanceReference reference) {
reference.IfInstanceIs<ISubscriber>(s => {
var eventAggregator = context.Kernel.Get<IEventAggregator>();
eventAggregator.Unsubscribe(s);
});
}
示例7: 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)
{
reference.IfInstanceIs<ContextPreservingResolutionRoot>(namedScopeResolutionRoot => DefineParentContext(context, namedScopeResolutionRoot));
}
开发者ID:ninject,项目名称:Ninject.Extensions.ContextPreservation,代码行数:9,代码来源:ContextPreservingResolutionRootActivationStrategy.cs