/// <summary> /// Dynamically creates a factory of<see cref="THandler"/>s and adds to the given <see cref="dictionary"/>. /// </summary> private void AddFactory <THandler, TItem> ( IDictionary <string, IFactory <THandler, TItem> > dictionary, HandlerTypes handlerType, HandlerFactoryTypeArguments typeArgs, FieldDefinition definition ) where THandler : IFieldHandler <TItem> where TItem : class { try { Type typeDefinition = GetFactoryTypeDefinition(handlerType, typeArgs.IsCollection); Type[] typeArguments = GetFactoryTypeArgs <TItem>(typeArgs, definition).ToArray(); Type factoryType = typeDefinition.MakeGenericType(typeArguments); var autoActivator = new AutoActivator(new SubstemHandlerDependencyResolver(typeArgs.GetterExpression, definition)); var factory = (IFactory <THandler, TItem>)autoActivator.CreateInstance(factoryType); dictionary.Add(definition.FieldName, factory); } catch (Exception ex) { string message = "Cannot add " + handlerType + " factory for this " + (typeArgs.IsCollection ? "collection" : "item"); throw new StemAttributeSetupException(message, ex); } }
public IRootStartInfo Get(IStemsCoreServices stemsServices, string startResourceName) { var autoActivator = new AutoActivator(stemsServices.DependencyResolver); var rootType = _rootTypeDictionary.GetType(startResourceName); var root = (Root)autoActivator.CreateInstance(rootType); return(new DerivedRootStartInfo(root)); }
public SubstemEngineSubContextCreator(Stem <TItem> stem) { _stem = stem; var autoActivator = new AutoActivator(_stem.Services.DependencyResolver); _substem = autoActivator.CreateInstance <TSubstem>(); _substem.SetParent(_stem); }
public IEnumerable <Type> GetStemTypes(IStemsCoreServices stemsServices) { var autoActivator = new AutoActivator(stemsServices.DependencyResolver); return(_rootTypeDictionary.GetAllTypes().Select(delegate(Type rootType) { var root = (Root)autoActivator.CreateInstance(rootType); return root.StartStemType; })); }
public IRestResource GetChild(string startResourceName) { IRootStartInfo startInfo = _startInfoFactory.Get(_configuration, startResourceName); Type stemType = startInfo.GetStemType(); if (stemType == null) { throw new ArgumentNullException(nameof(stemType), "Root class StartStemType cannot be null."); } IAxis axis = startInfo.GetAxis(_configuration, _request.User); _request.OnDispose += delegate { axis.Dispose(); }; var autoActivator = new AutoActivator(_configuration.DependencyResolver); var stem = (Stem)autoActivator.CreateInstance(stemType); stem.SetParent(axis); IDataSourceCollectionCreator creator = _creatorCache.GetOrAdd(startResourceName, delegate { Type stemGenericBaseType = stemType.GetGenericSubclass(typeof(Stem <>)); if (stemGenericBaseType == null) { throw new StemStartSetupException("The Stem class does not derive from Stem<>."); } Type itemType = stemGenericBaseType.GenericTypeArguments[0]; Type creatorType = typeof(DataSourceCollectionCreator <>).MakeGenericType(itemType); IDataSource dataSource = startInfo.GetDataSource(); // TODO same instance from first root reused? return((IDataSourceCollectionCreator)Activator.CreateInstance(creatorType, dataSource)); }); return(creator.GetRestCollection(stem)); }