I am trying to set up interception to work with Ninject, which we used as our dependency injection environment for a while.
I downloaded the interception extension from NuGet and tried it with both the Castle Dynamicproxy implementation and the LinFu implementation, but I couldn’t either work with our applications.
The lock gave an error when creating a proxy server in a class that did not have a constructor without parameters, since all service objects have their dependencies entered through the constructor, this is a problem. Error:
System.ArgumentException: Unable to instantiate class: emedia.RapidSystems.Subscriber.Presenters.RRSubmissionPresenter. Could not find constructor without parameters. Parameter Name: constructorArguments
The LinFu interceptor worked better, until the code called the method with a common parameter, after which it gave me the following:
System.ArgumentException: Generic types are not valid. Parameter Name: methodInfo
Here is a simplified version code for one of the classes I'm trying to intercept:
[LogCalls] public class Repository<T> : IRepository<T> where T : class { public virtual T GetEntity<TKey>(ObjectContext context, TKey key) { var entity = GetEntity(context, key, _emptyLoadingStrategy); return entity; } public virtual IQueryable<T> GetAll(ObjectContext context) { var query = GetAll(context, _emptyLoadingStrategy); return query; } public virtual T Add(ObjectContext context, T entity) { context.AddObject(EntitySetName(context), entity); return entity; }
Add and GetAll work fine, but an error occurs when GetEntity is called in the proxy.
At this point, I'm stuck, since no interceptor works with the code base. Did anyone get a Ninject hook that works with a real complex production system, not a simple demo class, and if so, how? I don't mind which interceptor I use while it works.
Or is the interception with Ninject still not mature enough, and I need to look at replacing everything with something else, like Unity?