public interface ITaskProvider
{
T GetTask<T>();
}
In the implementation of ITaskprovider below, as you see the IUserTask and IIdentityTask is being injected from property instead of constructor. The reason is that Windsor automatically instantiates the injected properties on runtime when accessed so that i dont have to put all the must injected dependencies in the constructor.
public class TaskProvider : ITaskProvider
{
public IUserTasks UserTasks { get; set; }
public IIdentityTasks IdentityTasks { get; set; }
public T GetTask<T>()
{
Type type = typeof(T);
if (type == typeof(IUserTasks)) return (T)this.UserTasks;
if (type == typeof(IIdentityTasks)) return (T)this.IdentityTasks;
return default(T);
}
}
In the controller I am injecting the ITaskProvider in the constructor.
public ITaskProvider TaskProvider { get; set; }
public AuctionsController(ITaskProvider taskProvider)
{
TaskProvider = taskProvider;
}
And here i call the taskprovider and its methods fine.
public ActionResult Index()
{
var userTasks = TaskProvider.GetTask<IUserTasks>();
var user = userTasks.FindbyId(guid);
}
Up to here, everything works fine.
I have been told that this is more like a service locator pattern and is violating dependency injection pattern and i want to know what is violating here.