English 中文(简体)
脱氧与Ninject有多个接口。 延期。 拦截。 Linfu
原标题:Proxy exposing multiple interfaces with Ninject.Extensions.Interception.Linfu

I m 采用Ninject。 延期。 Interception (更为具体地说,InterceptAttribute and Ninject. 延期。 拦截。 Linfu 代理实施我的C# app中的伐木机制,但当一个近似的类别实施若干接口时,我遇到了一些问题。

我推出一个交接班,从一个抽象的班子继承。

public class MyClass : AbstractClass, IMyClass {
  public string SomeProperty { get; set; }
}


public class LoggableAttribute : InterceptAttribute { ... }

public interface IMyClass {
  public string SomeProperty { get; set; }
}

public abstract class AbstractClass {

  [Loggable]
  public virtual void SomeMethod(){ ... }
}    

当我试图从占领者那里获得我的地图集时,可调取的<<>属性”即导致它退回代理。

var proxy = _serviceLocator.GetInstance<IMyClass>();

问题是,被送回的代理人只承认AbstractClass接口,揭露SomeMethod()。 顺便说一句,在我试图查阅现有的SomeProperty时,我收到了<条码>。

//ArgumentException
proxy.SomeProperty = "Hi";

In this case, is there a way of using mixin or some other technique to create a proxy exposing multiple interfaces?

成就

圣保罗

问题回答

我也遇到了类似的问题,即没有找到一种只用绝迹手段的棘手解决办法。 因此,我以更基本的方式从欧佩组织着手解决这一问题:组成。

Applied to your problem something like this would be my suggestion:

public interface IInterceptedMethods
{
    void MethodA();
}

public interface IMyClass
{
    void MethodA();
    void MethodB();
}

public class MyInterceptedMethods : IInterceptedMethods
{
    [Loggable]
    public virtual void MethodA()
    {
        //Do stuff
    }
}

public class MyClass : IMyClass
{
    private IInterceptedMethods _IInterceptedMethods;
    public MyClass(IInterceptedMethods InterceptedMethods)
    {
        this._IInterceptedMethods = InterceptedMethods;
    }
    public MethodA()
    {
        this._IInterceptedMethods.MethodA();
    }
    public Method()
    {
        //Do stuff, but don t get intercepted
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签