I’m developing and application and I use NInject framework to solve dependencies problems
but the constructors is too big. Some constructors have 5, 8, 10 parameters. and for solve this I have an Idea..
Instead code class like this.
public class UserBLL
{
private IA a;
private IB b;
...
UserBLL(IA a, IB b, IC c ...)
{
this.a = a;
this.b = b
...
}
}
I think code my classes like this.
public class UserBLL
{
private IA a;
private IB b;
...
UserBLL(IKernel kernel)
{
this.a = kernel.Get<IA>();
this.b = kernel.Get<IB>()
...
}
}
I would like to know if it’s a good idea and if it have any issue that I’ll face in the future.
No, I believe it is not good practice, you are trying to use
IKernelas supper factory, but remember you also create dependency toIKerneleverywhere in your code, which is not business class, it is infrastructure class.In your case, you might violate Single responsibility principle, try to divide your class to smaller classes will be the best suit in this case.