配置文件开关,数据库读写分离

This commit is contained in:
橙子
2021-10-26 15:09:07 +08:00
parent b29b6be734
commit 5d5452b531
30 changed files with 397 additions and 163 deletions

View File

@@ -5,16 +5,22 @@ using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Enum;
using Yi.Framework.Interface;
using Yi.Framework.Model.ModelFactory;
namespace Yi.Framework.Service
{
public class BaseService<T> : IBaseService<T> where T : class, new()
{
public DbContext _Db;
public BaseService(DbContext Db)
public DbContext _Db2;
public IDbContextFactory _DbFactory;
public BaseService(IDbContextFactory DbFactory)
{
_Db = Db;
_DbFactory = DbFactory;
_Db = DbFactory.ConnWriteOrRead(WriteAndReadEnum.Write);
_Db2 = DbFactory.ConnWriteOrRead(WriteAndReadEnum.Read);
}
public async Task<T> GetEntityById(int id)

View File

@@ -6,13 +6,14 @@ using System.Threading.Tasks;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface;
using Microsoft.EntityFrameworkCore;
using Yi.Framework.Model.ModelFactory;
namespace Yi.Framework.Service
{
public partial class MenuService:BaseService<menu>,IMenuService
{
public MenuService(DbContext Db):base(Db){ }
public MenuService(IDbContextFactory DbFactory):base(DbFactory){ }
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
{
@@ -30,7 +31,7 @@ namespace Yi.Framework.Service
public partial class MouldService:BaseService<mould>,IMouldService
{
public MouldService(DbContext Db):base(Db){ }
public MouldService(IDbContextFactory DbFactory):base(DbFactory){ }
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
{
@@ -48,7 +49,7 @@ namespace Yi.Framework.Service
public partial class RoleService:BaseService<role>,IRoleService
{
public RoleService(DbContext Db):base(Db){ }
public RoleService(IDbContextFactory DbFactory):base(DbFactory){ }
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
{
@@ -66,7 +67,7 @@ namespace Yi.Framework.Service
public partial class UserService:BaseService<user>,IUserService
{
public UserService(DbContext Db):base(Db){ }
public UserService(IDbContextFactory DbFactory):base(DbFactory){ }
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
{

View File

@@ -29,6 +29,7 @@ using System.Threading.Tasks;
using Yi.Framework.Model.Models;
using Yi.Framework.Interface;
using Microsoft.EntityFrameworkCore;
using Yi.Framework.Model.ModelFactory;
namespace Yi.Framework.Service
{
@@ -38,7 +39,7 @@ namespace Yi.Framework.Service
public partial class <#= fn #>Service:BaseService<<#= k #>>,I<#= fn #>Service
{
public <#= fn #>Service(DbContext Db):base(Db){ }
public <#= fn #>Service(IDbContextFactory DbFactory):base(DbFactory){ }
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
{

View File

@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Interface;
using Yi.Framework.Model;
using Yi.Framework.Model.ModelFactory;
using Yi.Framework.Model.Models;
namespace Yi.Framework.Service
@@ -14,7 +15,7 @@ namespace Yi.Framework.Service
public partial class UserService : BaseService<user>, IUserService
{
private IRoleService _roleService;
public UserService(DbContext Db, IRoleService roleService) : base(Db)
public UserService(IDbContextFactory DbFactory, IRoleService roleService) : base(DbFactory)
{
_roleService = roleService;
}