Альтернатива TypeInterceptor для Structuremap 3 - PullRequest
0 голосов
/ 04 октября 2019

Не удается найти функциональность TypeInterceptor в StructureMap 3.x и более поздних версиях. У меня есть ниже TypeInterceptor, написанный в StructureMap 2, который я не смог найти ни одной функциональности в StructureMap 3.x и более поздних версиях. Любая помощь для достижения ниже в SM 3 будет принята с благодарностью.

public class CachedRepositoryInterceptor:TypeInterceptor
{
    private readonly Type _openTargetType;
    private readonly Type _openWrapperType;


    public CachedRepositoryInterceptor(Type openTargetType, Type openWrapperType)
    {
        _openTargetType = openTargetType;
        _openWrapperType = openWrapperType;
    }

    public object Process(object target, IContext context)
    {
        var closedWith = target.GetType().GetGenericArguments()[0];
        var closedWrapperType = _openWrapperType.MakeGenericType(closedWith);
        return Activator.CreateInstance(closedWrapperType, target,context.GetInstance<ICacheProvider>());
    }

    public bool MatchesType(Type type)
    {
        return  type.ImplementsInterfaceTemplate(_openTargetType);
    }
}
...