StructureMap 4.6 中的 TypeInterceptor 实现

TypeInterceptor Implementation in StructureMap 4.6

谁能帮我把下面这行代码从 StructureMap 2.6 转换成 Structure Map 4.6

public class EventAggregatorInterceptor : TypeInterceptor
{
    public object Process(object target, IContext context)
    {
        IEventPublisher eventPublisher = context.GetInstance<IEventPublisher>();
        eventPublisher.RegisterHandlers(target);
        return target;
    }
    public bool MatchesType(Type type)
    {
        bool matchesType = type.ImplementsInterfaceTemplate(typeof(IEventHandler<>));
        return matchesType;
    }
}

如有任何帮助,我将不胜感激

我成功了,下面是代码

public class EventListenerRegistration : IInterceptorPolicy
{
    public string Description
    {
        get
        {
            return "Adds the constructed object to the EventAggregator";
        }
    }

    public IEnumerable<IInterceptor> DetermineInterceptors(Type pluginType, Instance instance)
    {
        if (instance.ReturnedType.FindInterfacesThatClose(typeof(IEventHandler<>)).Any())
        {
            Expression<Action<IContext, object>> register = (c, o) => c.GetInstance<IEventPublisher>().RegisterHandlers(o);
            yield return new ActivatorInterceptor<object>(register);
        }
    }
}

然后我在我的注册表构造函数中注册它

Policies.Interceptors(new EventListenerRegistration());