本文整理汇总了C#中Castle.DynamicProxy.ProxyGenerationOptions.AddMixinInstance方法的典型用法代码示例。如果您正苦于以下问题:C# ProxyGenerationOptions.AddMixinInstance方法的具体用法?C# ProxyGenerationOptions.AddMixinInstance怎么用?C# ProxyGenerationOptions.AddMixinInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle.DynamicProxy.ProxyGenerationOptions
的用法示例。
在下文中一共展示了ProxyGenerationOptions.AddMixinInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
/// <inheritdoc />
public object Create(object target, Type typeOfProxy,
Type[] additionalInterfacesOfProxy)
{
Check.MustNotNull("target", "target");
Check.MustNotNull("typeToProxy", "typeToProxy");
var aspects = _aspectsFinder.FindAspects(target.GetType());
if (!aspects.Any())
{
return target;
}
var options = new ProxyGenerationOptions
{
Selector = new PointcutAspectInterceptorSelector()
};
foreach (var instance in this.GetMixinInstances(target.GetType(), aspects))
{
options.AddMixinInstance(instance);
}
var interceptors = this.GetInterceptors(target.GetType(), aspects);
if (typeOfProxy.IsInterface)
{
return _proxyGenerator.CreateInterfaceProxyWithTarget(typeOfProxy,
additionalInterfacesOfProxy,
target, options, interceptors);
}
else
{
return _proxyGenerator.CreateClassProxyWithTarget(typeOfProxy,
additionalInterfacesOfProxy,
target, options, interceptors);
}
}
示例2: CanCreateMixinWithClassInterceptors
public void CanCreateMixinWithClassInterceptors()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new Dictionary<int, int>());
var builder = new ContainerBuilder();
builder.RegisterType<C>().EnableClassInterceptors(options);
builder.RegisterType<AddOneInterceptor>();
builder.RegisterType<AddTenInterceptor>();
var container = builder.Build();
var i = 10;
var cpt = container.Resolve<C>(TypedParameter.From(i));
var dict = cpt as IDictionary<int, int>;
Assert.NotNull(dict);
dict.Add(1, 2);
Assert.Equal(2, dict[1]);
dict.Clear();
Assert.Empty(dict);
}
开发者ID:jango2015,项目名称:Autofac.Extras.DynamicProxy,代码行数:25,代码来源:ClassInterceptorsWithOptionsFixture.cs
示例3: GetFieldInterceptionProxy
public override object GetFieldInterceptionProxy()
{
var proxyGenerationOptions = new ProxyGenerationOptions();
var interceptor = new LazyFieldInterceptor();
proxyGenerationOptions.AddMixinInstance(interceptor);
return ProxyGenerator.CreateClassProxy(PersistentClass, proxyGenerationOptions, interceptor);
}
示例4: CreateProxyGenerationOptions
/// <summary>
/// Creates a context - which is used to guid custom proxy
/// generation.
/// </summary>
/// <param name="mixins">Array of mixins to be registered</param>
/// <returns>A GeneratorContext instance</returns>
private static ProxyGenerationOptions CreateProxyGenerationOptions(object[] mixins)
{
ProxyGenerationOptions options = new ProxyGenerationOptions();
foreach (object mixin in mixins)
{
options.AddMixinInstance(mixin);
}
return options;
}
示例5: Mixin
public void Mixin()
{
var gen = new ProxyGenerator();
var opts = new ProxyGenerationOptions();
opts.AddMixinInstance(new HelloWorld());
opts.AddMixinInstance(new HelloWorld2());
var poco = (IUser)gen.CreateClassProxy(typeof(Poco), new[] { typeof(IUser) }, opts);
poco.Hello();
poco.Hello2();
poco.Hi();
}
示例6: Foo1
private void Foo1()
{
ProxyGenerator generator = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new ClassA());
ClassB objB = generator.CreateClassProxy<ClassB>(options, new MyCastleInterceptor());
objB.ActionB();
InterfaceA objA = objB as InterfaceA;
objA.ActionA();
}
示例7: GetTask
private static AsanaTask GetTask()
{
var options = new ProxyGenerationOptions();
var changeable = new Changeable();
options.AddMixinInstance(changeable);
var task = Generator.Instance.CreateClassProxy<AsanaTask>(options, new ChangeInterceptor(changeable));
changeable.TrackChanges = true;
return task;
//return new AsanaTask();
}
示例8: ServiceClientInterceptionIsPossibleWithMixins
public void ServiceClientInterceptionIsPossibleWithMixins()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new Dictionary<int, int>());
// Build the service-side container
var sb = new ContainerBuilder();
sb.RegisterType<TestService>().As<ITestService>();
// Build the client-side container with interception
// around the client proxy. Issue 361 was that there
// seemed to be trouble around getting this to work.
var cb = new ContainerBuilder();
cb.Register(c => CreateChannelFactory()).SingleInstance();
cb
.Register(c => c.Resolve<ChannelFactory<ITestService>>().CreateChannel())
.InterceptTransparentProxy(options, typeof(IClientChannel))
.UseWcfSafeRelease();
using (var sc = sb.Build())
{
// Start the self-hosted test service
var host = CreateTestServiceHost(sc);
host.Open();
try
{
using (var cc = cb.Build())
{
// Make a call through the client to the service -
// it should be intercepted.
var client = cc.Resolve<ITestService>();
var dict = client as IDictionary<int, int>;
Assert.IsNotNull(dict);
dict.Add(1, 2);
Assert.AreEqual(2, dict[1]);
dict.Clear();
Assert.IsEmpty(dict);
}
}
finally
{
host.Close();
}
}
}
示例9: Foo1
private void Foo1()
{
var container = new WindsorContainer();
container.Register(
Component.For<FooService, IFooService>()
);
ProxyGenerator generator = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new FooService());
FooController objB = generator.CreateClassProxy<FooController>(options, new FooInterceptor(new FooService()));
IFooService objA = objB as IFooService;
objA.Do();
}
示例10: Create
public AggregateRoot Create(Type aggregateType)
{
if (!typeof(AggregateRoot).IsAssignableFrom(aggregateType))
throw new ArgumentException("aggregateType must inherit AggregateRoot");
var snapshotType = _dynamicSnapshotAssembly.FindSnapshotType(aggregateType);
var snapshotableImplementer = _snapshotableImplementerFactory.Create(snapshotType);
var generator = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(snapshotableImplementer);
var proxy = (AggregateRoot)generator.CreateClassProxy(aggregateType, options);
((IHaveProxyReference)proxy).Proxy = proxy;
return proxy;
}
示例11: Create
public object Create(CreationContext context)
{
if (model.Service.IsInterface)
{
var interceptor = new LazyComponentInterceptor(innerActivator, context);
var mixin = new LazyTargetHostMixin(interceptor);
var proxyOptions = new ProxyGenerationOptions();
proxyOptions.AddMixinInstance(mixin);
var targetInterface = proxyGenerator.CreateInterfaceProxyWithoutTarget(model.Service, Type.EmptyTypes,
proxyOptions);
var proxy = proxyGenerator.CreateInterfaceProxyWithTargetInterface(model.Service, Type.EmptyTypes, targetInterface,
ProxyGenerationOptions.Default, interceptor);
return proxy;
}
// now what?
throw new NotImplementedException("Service type must be an interface");
}
示例12: RunCore
protected override object RunCore(IPluginServiceProvider serviceProvider)
{
CostLineType currentCostType = (CostLineType)serviceProvider.GetService(typeof(CostLineType));
CostManagerFactory costManagerFactory = CostManagerFactory.GetInstance(currentCostType);
object currentCostManagerObject = EAppRuntime.Instance.CurrentApp.ObjectContainer.Resolve(costManagerFactory.CurrentCostManagerType);
ProxyGenerator proxyGenerator = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(currentCostManagerObject);
ICostManager costManager =
(ICostManager)proxyGenerator.CreateClassProxy<CostManagerFactory>(options);
costManager.AddCostLine();
return costManager.CurrentDisplayedCostLines;
}
示例13: CustomizeOptions
protected override void CustomizeOptions(ProxyGenerationOptions context, IKernel kernel,
ComponentModel model, object[] arguments)
{
AspectDefinition aspect = (AspectDefinition) model.ExtendedProperties["aop.aspect"];
if (aspect == null) return;
MixinDefinitionCollection mixins = aspect.Mixins;
foreach(MixinDefinition definition in mixins)
{
Type mixinType = definition.TypeReference.ResolvedType;
try
{
context.AddMixinInstance( Activator.CreateInstance( mixinType ) );
}
catch(Exception e)
{
throw new ApplicationException("Could not instantiate mixin " + mixinType.FullName, e);
}
}
}
示例14: CanCreateMixinWithAttributeInterceptors
public void CanCreateMixinWithAttributeInterceptors()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new Dictionary<int, int>());
var builder = new ContainerBuilder();
builder.RegisterType<C>().As<IHasIAndJ>().EnableInterfaceInterceptors(options);
builder.RegisterType<AddOneInterceptor>();
builder.RegisterType<AddTenInterceptor>();
var cpt = builder.Build().Resolve<IHasIAndJ>();
var dict = cpt as IDictionary<int, int>;
Assert.NotNull(dict);
dict.Add(1, 2);
Assert.Equal(2, dict[1]);
dict.Clear();
Assert.Empty(dict);
}
开发者ID:jango2015,项目名称:Autofac.Extras.DynamicProxy,代码行数:23,代码来源:AttributedInterfaceInterceptionWithOptionsFixture.cs
示例15: InterceptsWithMixinWhenUsingExtendedPropertyAndType
public void InterceptsWithMixinWhenUsingExtendedPropertyAndType()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new Dictionary<int, int>());
var builder = new ContainerBuilder();
builder.RegisterType<CustomerService>()
.As<ICustomerService>()
.EnableInterfaceInterceptors(options);
var container = builder.Build();
var cs = container.Resolve<ICustomerService>();
var dict = cs as IDictionary<int, int>;
Assert.NotNull(dict);
dict.Add(1, 2);
Assert.Equal(2, dict[1]);
dict.Clear();
Assert.Empty(dict);
}
开发者ID:jango2015,项目名称:Autofac.Extras.DynamicProxy,代码行数:24,代码来源:InterceptorsChosenByMetadataWithOptionsFixture.cs