2011-12-09 121 views
2

我一直在努力使用wcf扩展和拦截dynamicproxy2扩展在wcf中工作的ninject。我基本上已经创建了一个时间属性,并将其全部用于基本场景。当我得到麻烦的是,当ninject模块中创建一个构造函数的参数我的服务绑定:Ninject与WCF和拦截(对于AOP)

Bind<IMyDependency>().To<MyDependency>(); 
Bind<IService1>().To<Service1>().WithConstructorArgument("dependency", Kernel.Get<IMyDependency>()); 

一切工作正常,但时间属性在我的服务1或MyDependency东西不会着火。

时间属性是标准的浮动在互联网上。唯一的其他部分的代码确实是CreateKernel方法是在Global.asax,它看起来像这样:

protected override IKernel CreateKernel() { 
    IKernel kernel = new StandardKernel(
     new NinjectSettings() { LoadExtensions = false }, 
     new WcfNinjectModule(), 
     new DynamicProxy2Module() 
    ); 
    return kernel; 
} 

感谢您的帮助!

马特

编辑12/12/2011:按照要求,我已经添加了下面一些细节: 整个WCF ninject模块:

public class WcfNinjectModule : NinjectModule 
{ 

    public override void Load() 
    { 
     Bind<IMyDependency>().To<MyDependency>(); 
     Bind<IService1>().To<Service1>(); 
    } 
} 

的创建全球核方法。 asax在上面,并且global.asax从NinjectWcfApplication继承。

服务方法是这样的:

public class Service1 : IService1 
{ 
    private IMyDependency _dependency; 

    public Service1() 
    { 
    } 
    public Service1(IMyDependency dependency) 
    { 
     _dependency = dependency; 
    } 

    [Time] 
    public virtual string GetData(string value) 
    { 
     return string.Format(_dependency.GetMyString(), value); 
    } 
} 
public interface IMyDependency 
{ 
    string GetMyString(); 
} 

public class MyDependency : IMyDependency 
{ 
    [Time] 
    public virtual string GetMyString() 
    { 
     return "Hello {0}"; 
    } 
} 

这是否帮助?

由于除去'WithConstructor'参数,时间拦截属性将在GetMyString上触发,但不会在GetData上触发。

马特

+0

请告诉我使用'.WithConstructorArgument的原因( “依赖性”,Kernel.Get ());'? Ninject会在没有它自己的情况下找到依赖关系。 如果这没有帮助,请您添加完整的问题,而不仅仅是部分。 –

+0

我只是希望尽可能明确 - 但即使我将其删除,也会遇到同样的问题。我会尝试在上面添加更多细节,但很难添加所有内容。 –

回答

0

一点更多的工作(和编写最后发表的文章编辑)后,事实证明,只是去掉WithConstructorArgument方法没有解决我的问题,现在一切都似乎是工作的罚款。

马特