Paul Duer
Paul Duer

Reputation: 1120

What is the correct usage of ORMLite with ASPNET Core 2.0?

Reading the documentation for ORMLite, it says to register the Connection Factory as a singleton if you're using an IoC container.

Is this the correct syntax for that with ASPNET Core 2.0? Or should I be using the .addDBContext method?

        var dbConnectString = Configuration["DBConnectString"];

        var userName = Configuration["DBUserId"];
        dbConnectString = dbConnectString.Replace("{your_username}", $"\'{userName}\'");

        var password = Configuration["DBPassword"];
        dbConnectString = dbConnectString.Replace("{your_password}", $"\'{password}\'");

        var dbFactory = new OrmLiteConnectionFactory(dbConnectString,SqlServerDialect.Provider);

        services.AddSingleton(dbFactory);

Upvotes: 0

Views: 493

Answers (1)

Tony Morris
Tony Morris

Reputation: 1007

AddDbContext is used for Entity Framework Core. Don't use that guy if you aren't using EF.

My method is as follows:

Upvotes: 1

Related Questions