public DocumentHttpService(IDocumentHttpServiceHandlerBase serviceHandler, IDocumentQueryFactory <TDocument> queryFactory, IDocumentStorageFactory storageFactory, ISystemDocumentStorageFactory systemStorageFactory, IBlobStorage blobStorage, IPerformanceLog performanceLog, ILog log) : base(performanceLog, log) { var storage = serviceHandler.AsSystem ? systemStorageFactory.GetStorage <TDocument>(serviceHandler.DocumentType) : storageFactory.GetStorage <TDocument>(serviceHandler.DocumentType); DocumentType = storage.DocumentType; CanGet = serviceHandler.CanGet; CanPost = serviceHandler.CanPost; CanDelete = serviceHandler.CanDelete; _serviceHandler = (IDocumentHttpServiceHandler <TDocument>)serviceHandler; _queryFactory = queryFactory; _blobStorage = blobStorage; _storage = storage; }
/// <summary> /// Создает сервисы по работе с документами на основе указанного обработчика. /// </summary> /// <param name="httpServiceHandler">Обработчик для сервиса по работе с документами.</param> public IEnumerable <IHttpService> CreateServices(IDocumentHttpServiceHandlerBase httpServiceHandler) { // Обработчик может быть универсальным и реализовывать сразу несколько интерфейсов var httpServiceHandlerType = httpServiceHandler.GetType(); // Создание типизированных сервисов var clrDocumentTypes = httpServiceHandlerType .GetInterfaces() .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IDocumentHttpServiceHandler <>)) .Select(i => i.GetGenericArguments()[0]); foreach (var clrDocumentType in clrDocumentTypes) { var handlerType = typeof(IDocumentHttpServiceHandlerBase); var serviceType = typeof(DocumentHttpService <>).MakeGenericType(clrDocumentType); var serviceFunc = typeof(Func <,>).MakeGenericType(handlerType, serviceType); var serviceFactory = (Delegate)_containerResolver.Resolve(serviceFunc); var service = (IHttpService)serviceFactory.FastDynamicInvoke(httpServiceHandler); yield return(service); } // Создание не типизированных сервисов if (httpServiceHandler is IDocumentHttpServiceHandler) { var serviceFactory = _containerResolver.Resolve <Func <IDocumentHttpServiceHandlerBase, DocumentHttpService> >(); var service = (IHttpService)serviceFactory.Invoke(httpServiceHandler); yield return(service); } }