在a.NET 6 web项目中使用SQL的依赖注入的最新推荐方法是什么?
.Net 6尚未更新当前的SQL文档。
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);
});发布于 2022-08-12 01:12:41
在Program.cs中
builder.Services.AddTransient<QueryFactory>((e) =>
{
var connection = new MySqlConnection("Host=localhost;Port=3306;User=user;Password=secret;Database=Users;SslMode=None");
var compiler = new MySqlServerCompiler();
return new QueryFactory(connection, compiler);
});https://stackoverflow.com/questions/73326864
复制相似问题