public Service(IRepository <T> repository) { try { // LoggerHelper.Instance.Warning(string.Format("开始创建[{0}]Service", EntityName)); EntityName = EntityExtensions.GetDescription(EType); this.repository = repository; this.repository.Queryable = IncludeNavigationProperties(repository.Queryable) .Where(PreparePredicate(null)); _UnitOfWork = repository.UnitOfWork as IQueryableUnitOfWork; // LoggerHelper.Instance.Warning(string.Format("成功创建[{0}]Service", EntityName)); } catch (Exception ex) { ex = new BusinessException(); HandleException(string.Format("创建[{0}]Service出错", EntityName), ex); } }
public void HandleException(string message = null, Exception ex = null) { message = (string.IsNullOrWhiteSpace(message)) ? "未知业务逻辑错误" : message.Trim(); if (ex == null) { ex = new BusinessException(message); _Logger.Error(ex); throw ex; } if (ex is AppException) { throw ex; } else { ex = new BusinessException(message, ex); _Logger.Error(ex); throw ex; } }
public override void Configure() { try { try { //注入IService IQueryableUnitOfWork WindsorRegistrar.Register(typeof(Db), typeof(Db)); base.Configure(); //var swcType = typeof(RepositoryWindsorConfigurator); //var assembly = swcType.Assembly; //var alltypes = assembly.GetTypes(); //var repositoryTypes = alltypes // .Where(t => t.IsInterface) // .ToList(); //foreach (var repositoryType in repositoryTypes) //{ // var implementationType = // alltypes.FirstOrDefault(t => t.GetInterface(repositoryType.Name) != null); // WindsorRegistrar.Register(repositoryType, implementationType); //} WindsorRegistrar.Register(typeof(RepositoryProvider), typeof(RepositoryProvider)); //WindsorRegistrar.RegisterAllFromAssemblies(assembly.FullName); } catch (Exception ex) { ex = new BusinessException("注入仓储对象失败!", ex); LoggerHelper.Instance.Error(ex); throw ex; } } catch (Exception ex) { throw new AppException("注入配置失败!", ex); } }