Skip to content

Commit bacbf92

Browse files
committed
Added DI for SqlConnection
1 parent 4a30df2 commit bacbf92

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22

3+
using Microsoft.Data.SqlClient;
4+
35
namespace Mssql.McpServer;
46

57
public interface ISqlConnectionFactory
68
{
7-
Task<Microsoft.Data.SqlClient.SqlConnection> GetOpenConnectionAsync();
8-
}
9-
9+
Task<SqlConnection> GetOpenConnectionAsync();
10+
}

MssqlMcp/MssqlMcp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static async Task Main(string[] args)
2727

2828
// Register ISqlConnectionFactory and Tools for DI
2929
_ = builder.Services.AddSingleton<ISqlConnectionFactory, SqlConnectionFactory>();
30-
_ = builder.Services.AddScoped<Tools>();
30+
_ = builder.Services.AddSingleton<Tools>();
3131

3232
// Register MCP server and tools (instance-based)
3333
_ = builder.Services

MssqlMcp/MssqlMcp/SqlConnectionFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22

3+
using Microsoft.Data.SqlClient;
4+
35
namespace Mssql.McpServer;
46

57
public class SqlConnectionFactory : ISqlConnectionFactory
68
{
7-
public async Task<Microsoft.Data.SqlClient.SqlConnection> GetOpenConnectionAsync()
9+
public async Task<SqlConnection> GetOpenConnectionAsync()
810
{
911
var connectionString = SqlConnectionManager.GetSqlConfig();
10-
var conn = new Microsoft.Data.SqlClient.SqlConnection(connectionString);
12+
var conn = new SqlConnection(connectionString);
1113
await conn.OpenAsync();
1214
return conn;
1315
}

0 commit comments

Comments
 (0)