本文整理汇总了C#中Castle.Core.DependencyModel.Init方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyModel.Init方法的具体用法?C# DependencyModel.Init怎么用?C# DependencyModel.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle.Core.DependencyModel
的用法示例。
在下文中一共展示了DependencyModel.Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDependency
/// <summary>
/// Invoked by
/// <see cref = "InitDependencies" />
/// in order to check if a dependency can be satisfied.
/// If not, the handler is set to a 'waiting dependency' state.
/// </summary>
/// <remarks>
/// This method registers the dependencies within the correct collection
/// or dictionary and changes the handler state to
/// <see cref = "HandlerState.WaitingDependency" />
/// </remarks>
/// <param name = "dependency"></param>
protected void AddDependency(DependencyModel dependency)
{
dependency.Init(model.ParametersInternal);
if (AddOptionalDependency(dependency))
{
return;
}
if (AddResolvableDependency(dependency))
{
return;
}
AddMissingDependency(dependency);
}
示例2: Create
private object Create(object factoryInstance, string factoryId, MethodInfo instanceCreateMethod, string factoryCreate, CreationContext context)
{
object instance;
var methodArgs = new List<object>();
try
{
var parameters = instanceCreateMethod.GetParameters();
foreach (var parameter in parameters)
{
var paramType = parameter.ParameterType;
if (paramType == typeof(IKernel))
{
methodArgs.Add(Kernel);
continue;
}
else if (paramType == typeof(CreationContext))
{
methodArgs.Add(context);
continue;
}
var dependency = new DependencyModel(parameter.Name, paramType, false);
dependency.Init(Model.HasParameters ? Model.Parameters : null);
if (!Kernel.Resolver.CanResolve(context, null, Model, dependency))
{
var message = String.Format(
"Factory Method {0}.{1} requires an argument '{2}' that could not be resolved",
instanceCreateMethod.DeclaringType.FullName, instanceCreateMethod.Name, parameter.Name);
throw new FacilityException(message);
}
var arg = Kernel.Resolver.Resolve(context, null, Model, dependency);
methodArgs.Add(arg);
}
instance = instanceCreateMethod.Invoke(factoryInstance, methodArgs.ToArray());
}
catch (Exception ex)
{
var message = String.Format("You have specified a factory " +
"('{2}' - method to be called: {3}) " +
"for the component '{0}' {1} that failed during invoke.",
Model.Name, Model.Implementation.FullName, factoryId, factoryCreate);
throw new FacilityException(message, ex);
}
if (Model.HasInterceptors)
{
try
{
instance = Kernel.ProxyFactory.Create(Kernel, instance, Model, context, methodArgs.ToArray());
}
catch (Exception ex)
{
throw new ComponentActivatorException("FactoryActivator: could not proxy " +
instance.GetType().FullName, ex);
}
}
return instance;
}