本文整理汇总了C#中IContext.PrepareForActivation方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.PrepareForActivation方法的具体用法?C# IContext.PrepareForActivation怎么用?C# IContext.PrepareForActivation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.PrepareForActivation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoInject
/*----------------------------------------------------------------------------------------*/
/// <summary>
/// Injects an existing instance of a service.
/// </summary>
/// <param name="instance">The existing instance to inject.</param>
/// <param name="context">The context in which the instance should be injected.</param>
protected override void DoInject(object instance, IContext context)
{
Type service = instance.GetType();
context.Instance = instance;
if (context.Binding == null)
context.PrepareForActivation(ResolveBinding(service, context));
Components.Activator.Activate(context);
if (context.ShouldTrackInstance)
context.Scope.Register(context);
}
示例2: DoResolve
/*----------------------------------------------------------------------------------------*/
#region Protected Methods: Instances
/// <summary>
/// Resolves an instance of a bound type.
/// </summary>
/// <param name="service">The type of instance to resolve.</param>
/// <param name="context">The context in which the instance should be resolved.</param>
/// <returns>The resolved instance.</returns>
protected override object DoResolve(Type service, IContext context)
{
if (context.Binding == null)
{
IBinding binding = ResolveBinding(service, context);
if (binding == null)
{
if (context.IsOptional)
{
if (Logger.IsDebugEnabled)
Logger.Debug("No bindings were found for the service {0}, ignoring since the request was optional", Format.Type(service));
return null;
}
else
{
// We couldn't resolve a binding for the service, so fail.
throw new ActivationException(ExceptionFormatter.CouldNotResolveBindingForType(service, context));
}
}
context.PrepareForActivation(binding);
}
if (Logger.IsDebugEnabled)
Logger.Debug("Resolving instance for {0}{1}", Format.Context(context), (context.IsEagerActivation ? " (eager activation)" : ""));
if (context.IsEagerActivation && !context.Plan.Behavior.SupportsEagerActivation)
{
if (Logger.IsDebugEnabled)
Logger.Debug("This is an eager activation request and the plan's behavior does not support it. Not actually activating an instance.");
return null;
}
if (context.Instance == null)
context.Instance = context.Plan.Behavior.Resolve(context);
if (context.ShouldTrackInstance)
context.Scope.Register(context);
return context.Instance;
}