I'm using dependency Injection to call my objects, so is there a neater way of adding more parameters in the constructor without making the constuctor signature long just like my case below?
public ObjectController(IParam1 param1, IParam2 param2, IParam3 param3,
IParam4 param4,IParam5 param6,IParam7 param8)
{
_param1= param1;
_param2 = param2;
_param3= param3;
_param4= param4;
_param5= param5;
_param6= param6;
_param7= param7;
_param8= param8;
}
CodePudding user response:
As the others have said, your controller has too much responsibility. I would recommend you break your functionality into Services/Business Logic services.
public class UserService : IUserService {
IParam _param;
IParam2 _param2;
public UserService(IParam param, IParam2 param2) {
_param = param;
_param2 = param2;
}
}
public class LoginService : ILoginService {
IParam _param;
IParam2 _param2;
public UserService(IParam param, IParam2 param2) {
_param = param;
_param2 = param2;
}
}
Then you can inject it into your controller
public Controller(IUserService userService, ILoginService loginService) { ... }
And if it it still too much I would recommend spliting your controller as well.