This is a migrated thread and some comments may be shown as answers.

AddTransient

2 Answers 150 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 25 Jun 2019, 06:09 PM

Hello,

Can someone please explain to me what the following line is doing:

this.services.AddTransient(ctx => new ReportsController(new ConfigurationService(env)));

I don't need to add any of my other controllers to the Startup.cs file. I would like to really understand this so as much detail as possible or a link to an article would be very helpful.

Thank you,

Scott

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 28 Jun 2019, 09:30 AM
Hi Scott,

When inheriting the ReportsControllerBase controller basic configuration is needed. An object implementing the IReportServiceConfiguration should be provided in order to configure the report service. This should be done in the controllers' constructor using static object to preserve the configuration between requests or using dependency injection.
ASP.NET Core has built-in support for dependency injection. We are using this functionality to pass the configuration of the Reporting Engine to the ReportsController instances. Since this is a lightweight service the service lifetime is set to transient. More on this topic can be found in Dependency injection in ASP.NET Core.

Regards,
Alena
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Scott
Top achievements
Rank 1
answered on 01 Jul 2019, 06:20 PM

Thank you very much for the detailed explanation, Alena. That really helped me understand what is happening.

Regards,

Scott

Tags
General Discussions
Asked by
Scott
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Scott
Top achievements
Rank 1
Share this question
or