Search code examples
c#sqlkata

SQLKATA ASP .NET CORE MVC 6 SETUP ISSUE


Im having issue in setting up of my SQLKATA in ASP core 6 MVC , the sample code in Sqlkata website used startup.cs to properly set the compiler. Now it ASP Core 6 no longer use startup, but used program.cs w/c incompatible to the code use by sqlkata w/c is :

services.Add<QueryFactory>(() => {

    // In real life you may read the configuration dynamically
    var connection = new MySqlConnection(
        "Host=localhost;Port=3306;User=user;Password=secret;Database=Users;SslMode=None"
    );

    var compiler = new MySqlCompiler();

    return new QueryFactory(connection, compiler);

});

I used builder.Services , but it doesnt accept the Add option.. Any idea what the issue and what todo?


Solution

  • Well this answer my inquiry , it seems I missed the DI (Dependecy Injection) , this link solved the issue, instead on using Add , it should be AddTransient with some modification with code :SQL Kata - Dependency Injection with .NET 6