views:

18

answers:

0

I'm working with Ninject 2.0.2
Ninject.Extensions.Interception
with DynamicProxy2
Castle.Core
Castle.DynamicProxy2

The injection worked fine. Then I inserted the wcf between controller and bl layers. For interaction between the layers I've used the Ninject.Extensions.Interception of Ian Davis. I've used the DynamicProxy2 for creating proxies with help of Castle.Core and Castle.DynamicProxy2. In my Bl layer in classes there are references to implementation Types in DAL Layer. The interceptor is working when I'm marking the attribute of [Inject] on any property existed in BL layer . It means that when I cut off my connections from BL to DAL it works but it's useless . So the question is how to preserve the option of addressing DAL even though I'm doing it through intercept method.

I've found only post that refers to the subject - http://dotnet.dzone.com/news/ninject-2-dependency-injection?utm_sourc...) but it doesn't explain how to deal with it. In every class I've already created a constructor and also put an [Inject] attribute above it.

Note: If I remove Inject from property of IMyClassDao , I'm getting the Injection but without the property - it stays dead. How can I revive it ? I've upgraded recently to Ninject 2.0.2 from 1.5 - can it related version issue ? Does anyone has a solution for it?

Kernel handling :

using Ninject; 
using Ninject.Modules; 
using System.Configuration; 
using System; 
using Ninject.Extensions.Interception; 
using Ninject.Extensions.Interception.Infrastructure.Language; 
using Ninject.Extensions.Interception.Request; 
private static IKernel createDefault() 
{ 
    IKernel _kernel = new StandardKernel(new 
    ControllerToBLModule(),new NHibernateModule(), new BlToDalModule()); 
    _kernel.Intercept(doIntercept).With<ControllerToBlInterceptor>(); 
    return _kernel; 
} 

in controller to bl:

public class ControllerToBLModule : NinjectModule 
{ 
    public override void Load() 
    { 
        Bind<IMyInterfaceBL>().To<MyClassBL>().InRequestScope(); 
    } 
} 

in bl to dal :

public class BlToDalModule : NinjectModule 
{ 
    public override void Load() 
    { 
           Bind<IMyClassDao>().To<MyClassDaoImpl>().InRequestScope(); 

    } 
} 

So the code in my Bl is something like this

public class MyClassBL: GlobalBL , IMyInterfaceBL 
{ 
    [Inject] 
    public MyClassBL() : base() { } 
    [Inject] 
    public IMyClassDao  _daoInstance{get;set;} 
    public virtual IList<MyObject> GetMyObject() 
    { 
        ... 
    } 
} 

and in DAL :

public class MyClassDaoImpl : GlobalDAOImpl, IMyClassDao 
{ 
    [Inject] 
    public MyClassDaoImpl() : base() { } 
    public virtual  IList<MyObject> GetMyObjectDao() 
    { 
        ... 
    } 
}

the error I'm getting :
Execute
System.NotSupportedException: Parent does not have a default constructor. The default constructor must be explicitly defined.
at System.Reflection.Emit.TypeBuilder.DefineDefaultConstructorNoLock(MethodAtt ributes attributes)
at System.Reflection.Emit.TypeBuilder.DefineDefaultConstructor(MethodAttribute s attributes)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(Type Builder type) in e:\horn.horn\ioc\castle.dynamicproxy\Working-2.2\src ....

Does anyone have any idea on how I can preserve the hierarchy of addressing the layers through Ninject during using the intercept method ?