Posted 24 January 2023, 8:26 am EST
Hi,
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
Startup.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDataSetsService dataSetsService)
{
...
app.UseReporting(settings =>
{
settings.UseFileStore(ResourcesRootDirectory);
settings.UseDataProviders(new GrapeCity.ActiveReports.Web.Viewer.DataProviderInfo[]
{
new GrapeCity.ActiveReports.Web.Viewer.DataProviderInfo("EpmReportData",
typeof(EpmReportDataProviderFactory).AssemblyQualifiedName,
typeof(EpmReportConnectionAdapter).AssemblyQualifiedName),
});
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();
}
}