Inject service into custom data provider

Posted by: marcon on 23 January 2023, 11:26 pm EST

    • Post Options:
    • Link

    Posted 23 January 2023, 11:26 pm EST


    I created a custom data provider and I want to know if is possible to inject services into my class that implements DbProviderFactory.

    Here is my code


    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDataSetsService dataSetsService) 
    	app.UseReporting(settings =>
    	  settings.UseDataProviders(new GrapeCity.ActiveReports.Web.Viewer.DataProviderInfo[]
    		new GrapeCity.ActiveReports.Web.Viewer.DataProviderInfo("EpmReportData",
    	  settings.UseCompression = true;

    EpmReportDataProviderFactory.cs (Here I want to inject HttpContextAccessor, but is given an exception)

    public class EpmReportDataProviderFactory : DbProviderFactory
      private IHttpContextAccessor _accessor;
      public EpmReportDataProviderFactory(IHttpContextAccessor accessor)
    	_accessor = accessor;
      /// <summary>
      /// Returns a new instance of the <see cref="EpmReportCommand"/>.
      /// </summary>
      public override DbCommand CreateCommand()
        return new EpmReportCommand(_accessor);
      /// <summary>
      /// Returns a new instance of the <see cref="EpmReportConnection"/>.
      /// </summary>
      public override DbConnection CreateConnection()
    	return new EpmReportConnection();
  • Posted 26 January 2023, 4:06 pm EST


    What exception are you getting? Please share a sample application reproducing this issue so we can reproduce this issue at our end and investigate further on this.

  • Posted 30 January 2023, 12:56 am EST

    This is the exception:

    details: “Constructor on type ‘WebDesignerCustomDataProviders.EpmReportDataProviderFactory’ not found.”

    message: “Failed rendering document”

    severity: “error”

    Here is the sample. You can get the above exception trying to open the file DemoReport.rdlx

    activereports WebSamples16 main

  • Posted 31 January 2023, 4:05 pm EST

    Hi Macron,

    I have discussed this with the development team[AR-30125]. Currently, it is not possible to inject dependencies in the Custom Data Provider for ActiveReports. As of now I would suggest you to have the IHttpContextAccessor as a static variable.

    Could you please let us in on your use case so we can decide whether we should add an option to inject dependencies in the Custom Data Provider?

  • Posted 2 February 2023, 10:24 pm EST

    Thank you akshay.rajput!

    The suggestion using static variable worked!


Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels