How to use Entity Framework with a Content Finder

I am trying to use a content finder to return items from a database using entity framework.

When I do this I get the error below:

AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ContentFinder Lifetime: Singleton ImplementationType: ContentFinder': Cannot consume scoped service 'DataContext' from singleton 'ContentFinder'.)

I totally get the error, but I’m not sure how to solve it, when I have no control over how content finders are registered

Any thoughts?

@Nik helped with this one, you need to register entity framework as transient

builder.Services.AddDbContext<DataContext>(options =>
{
    options.UseSqlServer("Name=ConnectionStrings:DataDb");
}, ServiceLifetime.Transient, ServiceLifetime.Transient);

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.