Not sure what to do here. invocationInfo.Proceed () always fails when trying to intercept a factory that has a constructor injection.
var container = new ServiceContainer();
container.Register<ICool,Cool>();
container.Register<ILogger, Logger>();
container.Register<IInterceptor, LoggingInterceptor>();
container.Register<int, IAwesome>((factory, value) => new Awesome(value, factory.GetInstance<ICool>()));
container.Intercept(sr => sr.ServiceType == typeof(IAwesome), sf => sf.GetInstance<IInterceptor>());
var awesome = container.GetInstance<int,IAwesome>(100);
awesome.Yo();
cannot execute this method on my interceptor.
public class LoggingInterceptor : IInterceptor
{
private ILogger _logger;
public LoggingInterceptor(ILogger logger)
{
_logger = logger;
}
public object Invoke(IInvocationInfo invocationInfo)
{
var returnValue = invocationInfo.Proceed();
return returnValue;
}
}
An exception:
An exception of type "System.InvalidCastException" occurred in LightInject.dll, but was not processed in the user code
Additional Information: It is not possible to pass an object of type "System.Func`1 [ConsoleApplication1.IAwesome]" to enter "System.Object []".
Sorry, I could not create a new tag for Lightinject. Not enough rep: /
source
share