LinqMetaData and QueryFactory Instances

Posts   
 
    
Posts: 12
Joined: 11-Aug-2017
# Posted on: 10-Apr-2024 17:11:31   

We have a project running: LLBLGen 5.10.1 - SelfServicing (Two Classes) - SQL Server 2017 - .NET Framework 4.8

In the context of a web application, I was just wondering what the correct instantiation and lifetime for LinqMetaData and QueryFactory would be when they are in a Repository registered as a Service in Dependency Injection.

using Autofac.Extensions.DependencyInjection;
using Autofac.Integration.Web;
using Autofac.Integration.WebApi;
using Microsoft.Extensions.DependencyInjection;

// Provider that holds the application container.
static IContainerProvider _containerProvider;

// Instance property that will be used by Autofac HttpModules to resolve and inject dependencies.
public IContainerProvider ContainerProvider
{
    get { return _containerProvider; }
}

public class Global : HttpApplication, IContainerProviderAccessor
{
    void RegisterServices(CommonSettings settings)
    {
        var services = new ServiceCollection();
        .
        .
        .
        services.AddScoped<InvoiceRepository>();

        // Build up your application container and register your dependencies.
        var containerBuilder = new ContainerBuilder();
        containerBuilder.Populate(services);

        var container = containerBuilder.Build();
        _containerProvider = new ContainerProvider(container);
        GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
    }
}
public class InvoiceRepository
{
    readonly QueryFactory qf;

    public InvoiceRepository()
    {
        qf = new QueryFactory();
    }

    public async Task<InvoiceDTO> GetInvoiceAsync(Guid id)
    {
        // Is this better
         var q = qf.Create();
    }

    public async Task<InvoiceDTO> GetInvoiceAsync(Guid id)
    {
        // Or is this better
         var qf = new QueryFactory();
         var q = qf.Create();
    }

}

Our database does have over 300 tables so there are hudnreds of Objects in Managed Memory in the Diagnostics Tools (when debugging). Tons of Func<>, Action<>, ....StaticMetaData ...Factory, all related to SD.LLBLGen.Pro.

I am slowly replacing all LINQ queries with QuerySpec through the solution.

Attachments
Filename File size Added on Approval
memory.png 69,001 10-Apr-2024 17:11.48 Approved
Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 11-Apr-2024 00:20:53   

Use them on a per call basis, don't keep them in memory.