【问题标题】:SQLKATA ASP .NET CORE MVC 6 SETUP ISSUESQLKATA ASP .NET CORE MVC 6 安装问题
【发布时间】:2022-08-14 19:31:58
【问题描述】:

我在 ASP core 6 MVC 中设置我的 SQLKATA 时遇到问题,Sqlkata 网站中的示例代码使用 startup.cs 正确设置编译器。现在它的 ASP Core 6 不再使用启动,而是使用 program.cs w/c 与 sqlkata w/c 使用的代码不兼容:

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);

});

我使用了 builder.Services ,但它不接受 Add 选项。知道什么问题和做什么?

  • “不接受”是什么意思?您是否缺少using 声明?
  • 是的,我确实使用过 SqlKata.Compilers;使用 SqlKata.Execution;
  • 我把它放在 program.cs builder.Services.Add<QueryFactory> ( ( ) => { // 在现实生活中你可以动态读取配置 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); 但我收到一条通知,说明它 Iservice 集合不包含添加

标签: c# sqlkata


【解决方案1】:

好吧,这回答了我的询问,似乎我错过了 DI (Dependecy Injection),这个链接解决了这个问题,而不是使用 Add ,它应该是 AddTransient 并用代码进行了一些修改:SQL Kata - Dependency Injection with .NET 6

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 2012-06-16
    • 2018-11-18
    • 2018-06-07
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多