In my previous project, I used Ninject to achieve autogeneration of actions. I had a generic ActionsFactory interface, which looked like this:
public interface IActionsFactory
{
TAction GetAction<TAction>();
}
Ninject was configured to bind this interface to a factory:
kernel.Bind<IActionsFactory>().ToFactory(() => new GenericFactoryMethodInstanceProvider());
public class GenericFactoryMethodInstanceProvider : StandardInstanceProvider
{
protected override string GetName(MethodInfo methodInfo, object[] arguments)
{
return null;
}
}
With this, I could reference in my controllers only IActionFactory
, without the need to reference all of the actions, like this:
public class SomeController : ApiController
{
private readonly IActionsFactory
public SomeController(IActionsFactory actionsFactory)
{
this.actionsFactory = actionsFactory;
}
[HttpGet]
public async Task<Foo> GetFoo()
{
retutn await actionsFactory.GetAction<IFooAction>().GetSomeFoo();
}
}
The question is: how can I achieve something similar with Lightinject?