AddTransient

3 posts, 1 answers
  1. Scott
    Scott avatar
    46 posts
    Member since:
    Aug 2011

    Posted 25 Jun Link to this post

    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. Answer
    Nasko
    Admin
    Nasko avatar
    1051 posts

    Posted 28 Jun Link to this post

    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
  3. Scott
    Scott avatar
    46 posts
    Member since:
    Aug 2011

    Posted 01 Jul in reply to Nasko Link to this post

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

    Regards,

    Scott

Back to Top