我想我解决了这个问题。
我没有使用Proxy.Mixins,而是创建了一个自定义Activator ()
Public Class MixInActivator(Of T)
Inherits Castle.MicroKernel.ComponentActivator.DefaultComponentActivator
Public Sub New(ByVal model As Castle.Core.ComponentModel, ByVal kernel As Castle.MicroKernel.IKernel, ByVal OnCreation As Castle.MicroKernel.ComponentInstanceDelegate, ByVal OnDestruction As Castle.MicroKernel.ComponentInstanceDelegate)
MyBase.New(model, kernel, OnCreation, OnDestruction)
End Sub
Protected Overrides Function InternalCreate(ByVal context As Castle.MicroKernel.CreationContext) As Object
Dim obj As Object = MyBase.InternalCreate(context)
If GetType(T).IsAssignableFrom(obj.GetType) = False Then
Dim options As New Castle.DynamicProxy.ProxyGenerationOptions
Dim gen As New Castle.DynamicProxy.ProxyGenerator
options.AddMixinInstance(Kernel.Resolve(Of T))
obj = gen.CreateInterfaceProxyWithTarget(Model.Service, obj, options)
End If
Return obj
End Function
End Class
所以现在,组件是这样注册的
container.Register(Component.For(Of ICat) _
.ImplementedBy(Of Cat) _
.LifeStyle.Is(Castle.Core.LifestyleType.Transient) _
.Activator(Of MixInActivator(Of IMixin)))
而IMixin注册如下
container.Register(Component.For(Of IMixin) _
.ImplementedBy(Of MyMixin) _
.LifeStyle.Is(Castle.Core.LifestyleType.Transient) _
.Named("MyMixin"))