Пример #1
0
        public DynamicQuery(IModelDescriptorCollection descriptors,
                            IServiceProvider serviceProvider,
                            IQueryRuleCollection queryRuleCollection)
        {
            if (descriptors == null)
            {
                throw new ArgumentNullException(nameof(descriptors));
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }
            var descriptor  = descriptors[typeof(T)] ?? throw new InvalidOperationException($"Missing descriptor of dto {typeof(T).Name}");
            var contextType = descriptor.Bag.__Context__ ?? throw new InvalidOperationException($"Missing db context for descriptor of dto {typeof(T).Name}");
            var context     = serviceProvider.GetService(contextType) ?? throw new InvalidOperationException($"Can not resolve db context {contextType.Name}");
            var map         = (Dictionary <string, string>)descriptor.SourceMap;

            Descriptor  = descriptor;
            ContextType = contextType;
            Context     = context;
            EntityMap   = map;
            _query      = (IDynamicQuery <T>)Activator.CreateInstance(
                typeof(QueryWrapper <,>).MakeGenericType(descriptor.SourceType, typeof(T)),
                context, descriptor, serviceProvider, queryRuleCollection, (IDictionary <string, string>)map);
        }
 public NotSupportedQueryRepositoryWrapper(DbContext dbContext,
                                           ModelDescriptor descriptor,
                                           IServiceProvider serviceProvider,
                                           IQueryRuleCollection queryRuleCollection,
                                           // ReSharper disable twice UnusedParameter.Local
                                           IDictionary <string, string> map,
                                           IEnumerable <IUpdateRule> rules,
                                           IMapper mapper) : base(dbContext, descriptor, serviceProvider, queryRuleCollection, map)
 {
     _context = dbContext;
 }
Пример #3
0
 public QueryWrapper(DbContext dbContext,
                     ModelDescriptor descriptor,
                     IServiceProvider serviceProvider,
                     IQueryRuleCollection queryRuleCollection,
                     IDictionary <string, string> map)
 {
     _originQuery         = descriptor.Bag.IsQueryType ? dbContext.Query <T>().AsQueryable() : dbContext.Set <T>().AsQueryable();
     _query               = _originQuery;
     _queryRuleCollection = queryRuleCollection;
     _serviceProvider     = serviceProvider;
     _map    = map ?? (Dictionary <string, string>)descriptor.SourceMap;
     _select = (Expression <Func <T, TResult> >)descriptor.SelectExpression ?? throw new InvalidOperationException($"The entity {descriptor.SourceType.Name} is required to map to the data transfer object {descriptor.DataTransferObjectType.Name}");
 }
Пример #4
0
 public RepositoryWrapper(DbContext dbContext,
                          ModelDescriptor descriptor,
                          IServiceProvider serviceProvider,
                          IQueryRuleCollection queryRuleCollection,
                          IDictionary <string, string> map,
                          IEnumerable <IUpdateRule> rules,
                          IMapper mapper) : base(dbContext, descriptor, serviceProvider, queryRuleCollection, map)
 {
     _context     = dbContext;
     _descriptor  = descriptor;
     _dbSet       = dbContext.Set <T>();
     _primaryKeys = _descriptor.DtoPrimaryKeyProperties.Select(p => p.MemberInfo).ToArray();
     _rules       = rules;
     _mapper      = mapper;
 }
Пример #5
0
        public DynamicRepository(IModelDescriptorCollection descriptors,
                                 IServiceProvider serviceProvider,
                                 IQueryRuleCollection queryRuleCollection,
                                 IEnumerable <IUpdateRule> rules,
                                 IMapper mapper,
                                 IUnitOfWork unitOfWork) : base(descriptors, serviceProvider, queryRuleCollection)
        {
            if (rules == null)
            {
                throw new ArgumentNullException(nameof(rules));
            }
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }
            var repoType = Descriptor.Bag.IsQueryType ? typeof(NotSupportedQueryRepositoryWrapper <,>) : typeof(RepositoryWrapper <,>);

            _repo = (IDynamicRepository <T>)Activator.CreateInstance(
                repoType.MakeGenericType(Descriptor.SourceType, typeof(T)),
                Context, Descriptor, serviceProvider, queryRuleCollection, EntityMap, rules, mapper);
            unitOfWork?.Use(_repo);
        }