示例#1
0
        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));
        }