You've already forked CsharpTemplate
Add project files.
This commit is contained in:
10
ConsoleTemplate/Contexts/IDBContext.cs
Normal file
10
ConsoleTemplate/Contexts/IDBContext.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using MySqlConnector;
|
||||
|
||||
namespace ConsoleTemplate.Contexts
|
||||
{
|
||||
internal interface IDBContext
|
||||
{
|
||||
Object GetWriteConn();
|
||||
Object GetReadConn();
|
||||
}
|
||||
}
|
38
ConsoleTemplate/Contexts/MysqlDBContext.cs
Normal file
38
ConsoleTemplate/Contexts/MysqlDBContext.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace ConsoleTemplate.Contexts
|
||||
{
|
||||
internal class MysqlDBContext : IDBContext
|
||||
{
|
||||
private IConfiguration _config;
|
||||
private MySqlConnection _connection;
|
||||
private MySqlCommand _cmd;
|
||||
private string _connectionStringRead;
|
||||
private string _connectionStringWrite;
|
||||
|
||||
public MysqlDBContext(IConfiguration configuration)
|
||||
{
|
||||
_config = configuration;
|
||||
_connectionStringRead = _config.GetConnectionString("ReadDB").ToString();
|
||||
_connectionStringWrite = _config.GetConnectionString("WriteDB").ToString();
|
||||
}
|
||||
|
||||
public Object GetReadConn()
|
||||
{
|
||||
_connection = new MySqlConnection(_connectionStringWrite);
|
||||
return _connection;
|
||||
}
|
||||
|
||||
public Object GetWriteConn()
|
||||
{
|
||||
_connection = new MySqlConnection(_connectionStringRead);
|
||||
return _connection;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user