本文整理汇总了C#中Castle.Core.ComponentModel.ObtainProxyOptions方法的典型用法代码示例。如果您正苦于以下问题:C# ComponentModel.ObtainProxyOptions方法的具体用法?C# ComponentModel.ObtainProxyOptions怎么用?C# ComponentModel.ObtainProxyOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle.Core.ComponentModel
的用法示例。
在下文中一共展示了ComponentModel.ObtainProxyOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessModel
public void ProcessModel(IKernel kernel, ComponentModel model)
{
if (model.Configuration == null)
{
return;
}
var mixins = model.Configuration.Children["mixins"];
if (mixins == null)
{
return;
}
var mixinReferences = new List<ComponentReference<object>>();
foreach (var mixin in mixins.Children)
{
var value = mixin.Value;
var mixinComponent = ReferenceExpressionUtil.ExtractComponentKey(value);
if (mixinComponent == null)
{
throw new Exception(
String.Format("The value for the mixin must be a reference to a component (Currently {0})", value));
}
mixinReferences.Add(new ComponentReference<object>("mixin-" + mixinComponent, mixinComponent));
}
if (mixinReferences.Count == 0)
{
return;
}
var options = model.ObtainProxyOptions();
mixinReferences.ForEach(options.AddMixinReference);
}
示例2: Create
public override object Create(IKernel kernel, object instance, ComponentModel model,
CreationContext context, params object[] constructorArguments)
{
var channelHolder = instance as IWcfChannelHolder;
if (channelHolder == null)
{
throw new ArgumentException(string.Format("Given instance is not an {0}", typeof(IWcfChannelHolder)), "instance");
}
if (channelHolder.RealProxy == null)
{
return channelHolder.Channel;
}
if (model.Services.Count() > 1)
{
throw new ArgumentException(string.Format(
"Component {0}, which was designated as a WCF proxy exposes {1} services. The facility currently only supports single-service components.",
model.Name, model.Services.Count()));
}
var isDuplex = IsDuplex(channelHolder.RealProxy);
var proxyOptions = model.ObtainProxyOptions();
var serviceContract = model.GetServiceContract();
var generationOptions = CreateProxyGenerationOptions(serviceContract, proxyOptions, kernel, context);
var additionalInterfaces = GetInterfaces(model.Services, proxyOptions, isDuplex);
var interceptors = GetInterceptors(kernel, model, serviceContract, channelHolder, context);
return generator.CreateInterfaceProxyWithTarget(typeof(IWcfChannelHolder),
additionalInterfaces, channelHolder, generationOptions, interceptors);
}
示例3: BuildComponentModel
public void BuildComponentModel(IKernel kernel, ComponentModel model)
{
if (!mixIns.Any())
{
return;
}
var options = model.ObtainProxyOptions();
foreach (var mixIn in mixIns)
{
options.AddMixinReference(mixIn);
}
}
示例4: AddTypedFactoryEntry
public void AddTypedFactoryEntry(FactoryEntry entry)
{
var model = new ComponentModel(new ComponentName(entry.Id, true), new[] { entry.FactoryInterface }, typeof(Empty),
new Arguments().Insert("typed.fac.entry", entry))
{ LifestyleType = LifestyleType.Singleton };
model.Interceptors.Add(new InterceptorReference(typeof(FactoryInterceptor)));
var proxyOptions = model.ObtainProxyOptions();
proxyOptions.OmitTarget = true;
((IKernelInternal)Kernel).AddCustomComponent(model);
}
示例5: Create
public override object Create(IProxyFactoryExtension customFactory, IKernel kernel, ComponentModel model, CreationContext context,
params object[] constructorArguments)
{
var interceptors = ObtainInterceptors(kernel, model, context);
var proxyOptions = model.ObtainProxyOptions();
var proxyGenOptions = CreateProxyGenerationOptionsFrom(proxyOptions, kernel, context, model);
CustomizeOptions(proxyGenOptions, kernel, model, constructorArguments);
var builder = generator.ProxyBuilder;
var proxy = customFactory.Generate(builder, proxyGenOptions, interceptors, model, context);
CustomizeProxy(proxy, proxyGenOptions, kernel, model);
ReleaseHook(proxyGenOptions, kernel);
return proxy;
}
示例6: CollectFromConfiguration
protected virtual void CollectFromConfiguration(ComponentModel model)
{
if (model.Configuration == null)
{
return;
}
var interceptors = model.Configuration.Children["interceptors"];
if (interceptors == null)
{
return;
}
CollectInterceptors(model, interceptors);
var options = model.ObtainProxyOptions();
CollectSelector(interceptors, options);
CollectHook(interceptors, options);
}
示例7: ShouldCreateProxy
public bool ShouldCreateProxy(ComponentModel model)
{
if (model.HasInterceptors)
{
return true;
}
var options = model.ObtainProxyOptions(false);
if (options != null && options.RequiresProxy)
{
return true;
}
if (selectors != null && selectors.Any(s => s.HasInterceptors(model)))
{
return true;
}
return false;
}
示例8: Create
public override object Create(IKernel kernel, object instance, ComponentModel model,
CreationContext context, params object[] constructorArguments)
{
var channelHolder = instance as IWcfChannelHolder;
if (channelHolder == null)
{
throw new ArgumentException(string.Format("Given instance is not an {0}", typeof(IWcfChannelHolder)), "instance");
}
var isDuplex = IsDuplex(channelHolder.RealProxy);
var proxyOptions = model.ObtainProxyOptions();
var serviceContract = model.GetServiceContract();
var remainingServices = model.Services.Except(new[] { serviceContract });
var generationOptions = CreateProxyGenerationOptions(serviceContract, proxyOptions, kernel, context);
generationOptions.AddMixinInstance(channelHolder);
var additionalInterfaces = GetInterfaces(remainingServices, proxyOptions, isDuplex);
var interceptors = GetInterceptors(kernel, model, serviceContract, channelHolder, context);
return generator.CreateInterfaceProxyWithTargetInterface(serviceContract,
additionalInterfaces, channelHolder.Channel, generationOptions, interceptors);
}
示例9: ApplySynchronization
/// <summary>
/// Applies the synchronization support to the model.
/// </summary>
/// <param name = "model">The model.</param>
/// <param name = "kernel">The kernel.</param>
private void ApplySynchronization(ComponentModel model, IKernel kernel)
{
var options = model.ObtainProxyOptions();
model.Interceptors.Add(new InterceptorReference(typeof(SynchronizeInterceptor)));
var metaInfo = metaStore.GetMetaFor(model.Implementation);
if (metaInfo != null)
{
IInterceptorSelector userSelector = null;
if (options.Selector != null)
{
userSelector = options.Selector.Resolve(kernel, CreationContext.CreateEmpty());
}
options.Selector = new InstanceReference<IInterceptorSelector>(new SynchronizeInterceptorSelector(metaInfo, userSelector));
foreach (var reference in metaInfo.GetUniqueSynchContextReferences())
{
model.Dependencies.Add(new DependencyModel(reference.ComponentKey, reference.ServiceType, false));
}
}
}
示例10: BuildComponentModel
public void BuildComponentModel(IKernel kernel, ComponentModel model)
{
var options = model.ObtainProxyOptions();
options.Selector = selector;
}
示例11: BuildComponentModel
public void BuildComponentModel(IKernel kernel, ComponentModel model)
{
var options = model.ObtainProxyOptions();
options.AddAdditionalInterfaces(interfaces);
}
示例12: ConfigureProxyOptions
private void ConfigureProxyOptions(ComponentModel model)
{
if (controlProxyHook == null)
{
return;
}
var proxyOptions = model.ObtainProxyOptions();
proxyOptions.Hook = controlProxyHook;
}
示例13: RequiresTargetInstance
/// <summary>
/// Determines if the component requires a target instance for proxying.
/// </summary>
/// <param name="kernel"> The kernel. </param>
/// <param name="model"> The model. </param>
/// <returns> true if an instance is required. </returns>
public override bool RequiresTargetInstance(IKernel kernel, ComponentModel model)
{
var proxyOptions = model.ObtainProxyOptions();
return model.HasClassServices == false &&
proxyOptions.OmitTarget == false;
}
示例14: ApplyProxyBehavior
private static void ApplyProxyBehavior(ComponentProxyBehaviorAttribute behavior, ComponentModel model)
{
var options = model.ObtainProxyOptions();
#if !SILVERLIGHT
if (behavior.UseMarshalByRefProxy)
{
EnsureComponentRegisteredWithInterface(model);
}
options.UseMarshalByRefAsBaseClass = behavior.UseMarshalByRefProxy;
#endif
options.AddAdditionalInterfaces(behavior.AdditionalInterfaces);
if(model.Implementation.IsInterface)
{
options.OmitTarget = true;
}
}
示例15: BuildComponentModel
public void BuildComponentModel(IKernel kernel, ComponentModel model)
{
var options = model.ObtainProxyOptions();
options.Hook = hook;
}