Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telerik Reporting ObjectDataSource with dependency injection

I am developing an asp.net mvc 5 web application. There is a class library only for telerik reports[no trdx]. I am using TypeReportSource to resolve report and NeedDataSource event of report file to fetch data from database. In the whole project i am using constructor injection(structuremap) technique but here Constructor injection is not working as telerik report only supports parameterless constructor.

How to pass data to DataSource of the report? I do not want to add separate IoC container for the class library as it is shared by multiple project with separate configuration.

like image 324
Rased Dot Net Avatar asked Mar 27 '15 13:03

Rased Dot Net


1 Answers

In "Telerik Report Library" mode, the every report are composed by 3 files by default. Let's say i create a report named "ProductReport" in report project. it will generate ProductReport.cs, ProductReport.Designer.cs, ProductReport.resx

Following is the "ProductReport.cs" code:

public partial class ProductReport : Telerik.Reporting.Report
{
    public ProductReport()
    {
        //
        // Required for telerik Reporting designer support
        //
        InitializeComponent();

        //
        // TODO: Add any constructor code after InitializeComponent call
        //
    }
}

I think one of the option is to add another constructor with parameter(s) which you want to inject in to Report instance, include the data source, and remember to call "InitializeComponent()".

Another good side of this solution is, it will not impact the report designer usage, and the modification of the report items by designer itself.

like image 192
Ethan Wu Avatar answered Oct 15 '22 01:10

Ethan Wu