Ejemplo n.º 1
0
        public object GetService(Type serviceType)
        {
            IRequest request = resolutionRoot.CreateRequest(serviceType, null,
                                                            new Parameter[0], true, true);

            return(resolutionRoot.Resolve(request).SingleOrDefault());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves instances for the specified request. The instances are not actually resolved
        /// until a consumer iterates over the enumerator.
        /// </summary>
        /// <param name="request">The request to resolve.</param>
        /// <returns>
        /// An enumerator of instances that match the request.
        /// </returns>
        public override IEnumerable <object> Resolve(IRequest request)
        {
            if (base.CanResolve(request))
            {
                return(base.Resolve(request));
            }

            if (_parent.CanResolve(request, true))
            {
                return(_parent.Resolve(request));
            }

            try
            {
                return(base.Resolve(request));
            }
            catch (ActivationException)
            {
                try
                {
                    return(_parent.Resolve(request));
                }
                catch (ActivationException)
                {
                }

                throw;
            }
        }
Ejemplo n.º 3
0
        public object GetService(Type serviceType)
        {
            if (_resolver == null)
            {
                throw new ObjectDisposedException("this", "This scope has been disposed.");
            }

            return(_resolver.Resolve(CreateRequest(serviceType)).SingleOrDefault());
        }
Ejemplo n.º 4
0
        public object GetService(Type serviceType)
        {
            if (resolver == null)
            {
                throw new ObjectDisposedException("this", "This scope has been disposed");
            }

            IRequest request = resolver.CreateRequest(serviceType, null, new Parameter[0], true, true);

            return(resolver.Resolve(request).SingleOrDefault());
        }
Ejemplo n.º 5
0
        private static IEnumerable <object> GetResolutionIterator(IResolutionRoot root, Type service, Func <IBindingMetadata, bool> constraint, IEnumerable <IParameter> parameters, bool isOptional, bool isUnique)
        {
            Ensure.ArgumentNotNull(root, "root");

            var request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique);

            return(root.Resolve(request));
        }
Ejemplo n.º 6
0
        private static IEnumerable <object> GetResolutionIterator(IResolutionRoot root, Type service, Func <IBindingMetadata, bool> constraint, IEnumerable <IParameter> parameters, bool isOptional, bool isUnique)
        {
            Contract.Requires(root != null);
            Contract.Requires(service != null);
            Contract.Requires(parameters != null);

            var request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique);

            return(root.Resolve(request));
        }
Ejemplo n.º 7
0
        public static IEnumerable <T> TryGetAll <T>(this IResolutionRoot resolutionRoot)
        {
            var         request    = resolutionRoot.CreateRequest(typeof(IFoo), x => true, Enumerable.Empty <IParameter>(), true, false);
            IEnumerable results    = resolutionRoot.Resolve(request);
            IEnumerator enumerator = results.GetEnumerator();

            while (MoveNextIgnoringActivationException(enumerator))
            {
                yield return((T)enumerator.Current);
            }
        }
 public override IController CreateController(RequestContext requestContext, string controllerName)
 {
     //You can improve this later if you want -> you'll need to figure out if your controller will fit into this case
     //You can use marker interfaces, common supertype, etc... that's up to you
     if (controllerName.Equals("home", StringComparison.InvariantCultureIgnoreCase))
     {
         var controllerType       = typeof(HomeController);
         var isChild              = requestContext.RouteData.DataTokens.ContainsKey(ParentActionViewContextToken);
         var constructorArgument  = new ConstructorArgument("someName", (isChild) ? "Child" : "Nope");
         var requestForDependency = _resolutionRoot.CreateRequest(typeof(IServiceClient), null, new Parameter[] { constructorArgument }, true, true);
         var dependency           = _resolutionRoot.Resolve(requestForDependency).SingleOrDefault();
         return((IController)_resolutionRoot.Get(controllerType, new ConstructorArgument("service", dependency)));
     }
     //Will go through the default pipeline (IDependencyResolver will be called, not affecting DI of other controllers)
     return(base.CreateController(requestContext, controllerName));
 }
Ejemplo n.º 9
0
 public object GetService(Type serviceType)
 {
     return(resolutionRoot.Resolve(
                this.CreateRequest(serviceType)).SingleOrDefault());
 }
 /// <summary>
 /// Get services based on a type
 /// </summary>
 /// <param name="serviceType">ServiceType value</param>
 /// <returns>IRequest object</returns>
 public IEnumerable<object> GetServices(Type serviceType)
 {
     IRequest request = GetRequest(serviceType);
     return resolutionRoot.Resolve(request).ToList();
 }
Ejemplo n.º 11
0
        public IEnumerable <object> GetServices(Type serviceType)
        {
            var request = _resolutionRoot.CreateRequest(serviceType, null, new IParameter[0], true, true);

            return(_resolutionRoot.Resolve(request));
        }
Ejemplo n.º 12
0
 public IEnumerable <object> Resolve(IRequest request)
 {
     return(_parent.Resolve(request));
 }