using Infrastructure; using Infrastructure.Attribute; using SqlSugar.IOC; using ZR.Model.System; using ZR.Repository; using ZR.Service.IService; using ZR.Service.System.IService; using ZR.ServiceCore.Model; namespace ZR.Service { /// /// 注意:下面的AppService不要漏了 /// [AppService(ServiceType = typeof(IHelloService), ServiceLifetime = LifeTime.Transient)] public class HelloService : BaseService, IHelloService { /// /// 引用User服务 /// private readonly ISysUserService userService; /// /// /// /// public HelloService(ISysUserService userService) { this.userService = userService; } /// /// 数据库使用案例 /// /// /// public string SayHello(string name) { //构造函数式使用 var user = JsonConvert.SerializeObject(userService.GetFirst(f => f.UserId == 1)); Console.WriteLine(user); var postService = App.GetRequiredService(); Console.WriteLine(JsonConvert.SerializeObject(postService.GetId(1))); BaseRepository deptRepo = new(); Console.WriteLine(JsonConvert.SerializeObject(deptRepo.GetId(1))); var result = DbScoped.SugarScope.Queryable().Where(f => f.DictId == 1).First(); Console.WriteLine(JsonConvert.SerializeObject(result)); //切换库 //DbScoped.SugarScope.GetConnectionScope(2); GetFirst(x => x.CategoryId == 1); Context.Queryable().First(f => f.UserId == 1); return "Hello:" + name; } } }