We currently use a mix of either approach. Is there a (performance) benefit of one vs the other?
example 1: ILogicAPI injected into controller constructor:
services.AddScoped<ILogicAPI, LogicAPI>(sp =>
{
var httpClient = sp.GetRequiredService<IHttpClientFactory>().CreateClient();
return new LogicAPI(surveyConfig.SurveyApiProxyConfiguration(httpClient));
});
Controller:
public AssessmentController(
SurveyUIConfiguration configuration,
IAssessmentAPI assessmentApi,
ISurveyReviewAPI surveyReviewApi,
IAnswerAPI answerApi,
ITakerScreenAPI screenApi,
ILogicAPI logicApi,
IMasterSurveyErrorMessageTextsAPI errorAPI
)
{
this.assessmentApi = assessmentApi;
this.surveyReviewApi = surveyReviewApi;
this.answerApi = answerApi;
viewModelService = new ViewModelService(configuration, answerApi, screenApi, logicApi, errorAPI);
}
or example 2: new LogicAPI is instantiated in the controller
public AssessmentController(
IMasterSurveyErrorMessageTextsAPI errorAPI,
IBaseSurveyControllerServices services
) : base(services)
{
this.assessmentApi = new AssessmentAPI(SurveyApiSettings);
this.surveyReviewApi = new SurveyReviewAPI(SurveyApiSettings);
this.answerApi = new AnswerAPI(SurveyApiSettings);
var screenApi = new TakerScreenAPI(SurveyApiSettings);
var logicApi = new LogicAPI(SurveyApiSettings);
viewModelService = new ViewModelService(Configuration, answerApi, screenApi, logicApi, errorAPI);
}
HttpClientin those classes and then let the IoC container resolve it for you? Seems like you're doing too much heavy lifting that the container can do on your behalf.