Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

With reference to query #10383 - Please help some more #10397


User avatar
0
chrskrs created

Prerequisites What is your product version? 8.3 What is your product type (Angular or MVC)? MVC What is product framework type (.net framework or .net core)? .NET Core If issue related with ABP Framework What is ABP Framework version? 8.3

I am trying to intergare the EasyQuery reporting product into my Net Zero application but I have the following problem / question:

In Startup.cs class Easy query requires that the DB context be given in the Configure function like this:

endpoints.MapEasyQuery(options => { options.UseDbContext<MyDbContext>(services => new MyDbContext(...) }

How can Ido the new part seeing that aspnet zero uses IDbcontextProvider to get the dbcontext?

Your reply ismcagdas created 4 days agoSupport Team Hi,

You can solve this problem like this;

Add the code block below into Initialize Method of *WebHostModule.cs class;

Configuration.IocManager.IocContainer.Register(Component
.For(typeof(DbContextOptions<reedisaDbContext>)).UsingFactoryMethod((kernel, context) =>
    {
        var builder = new DbContextOptionsBuilder<reedisaDbContext>();
        builder.UseSqlServer(Configuration.DefaultNameOrConnectionString);
        return builder.Options;
     }));

However

I added the suggested code to my web.mvcModule.cs, as I do not use the Web Host project, but when
I run the app the system fails in Startup Configure

endpoints.MapEasyQuery(
                    options =>
                    {
                        options.UseDbContext<reedisaDbContext>();      <<===== fail here
                    });

message is

Application startup exception: System.Exception: Could not resolve a service of type 'Abp.EntityFrameworkCore.IDbContextProvider`1[[reedisa.EntityFrameworkCore.reedisaDbContext, reedisa.EntityFrameworkCore, Version=9.1.0.0, Culture=neutral, PublicKeyToken=null]]' for the parameter 'dbContextProvider' of method 'Configure' on type 'reedisa.Web.Startup.Startup'.

Thankyou for your help so far Regard Chris Krause


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @chrskrs

    Could you share which EasyQuery document you are following for integration ? The correct usage must be liek this I guess;

    public Startup(IWebHostEnvironment env)
    {
        Korzh.EasyQuery.AspNetCore.License.Key = "";
        Korzh.EasyQuery.AspNetCore.JSLicense.Key = "";
    }
    
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
    
        services.AddEasyQuery()
                .UseSqlManager();
    
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseEasyQuery(options => {
            options.UseDbContext<AppDbContext>();
        });
    }