You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
33 lines
1.0 KiB
using Microsoft.EntityFrameworkCore;
|
|
using Monitor.Models;
|
|
|
|
namespace DataBase.MySql.Tool
|
|
{
|
|
public sealed class DBTool
|
|
{
|
|
private static readonly Lazy<DBTool> MLazy = new Lazy<DBTool>(() => new DBTool());
|
|
|
|
public static DBTool Instance => MLazy.Value;
|
|
|
|
private AsyncLocal<MyDbContext> _dbContext = new AsyncLocal<MyDbContext>();
|
|
|
|
private DBTool()
|
|
{
|
|
}
|
|
|
|
public MyDbContext MyDbContext()
|
|
{
|
|
MyDbContext? myDbContext = _dbContext.Value;
|
|
if (myDbContext == null)
|
|
{
|
|
DbContextOptionsBuilder<MyDbContext> optionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
|
|
optionsBuilder.UseMySQL<MyDbContext>(
|
|
"Data Source=localhost;Initial Catalog=chassis_track_swap;User ID=root;Password=123456;sslmode=none;");
|
|
myDbContext = new MyDbContext(optionsBuilder.Options);
|
|
}
|
|
|
|
_dbContext.Value = myDbContext;
|
|
return myDbContext;
|
|
}
|
|
}
|
|
} |