Exemplo n.º 1
0
        /// <summary>
        ///     Obtains an activator for the given <paramref name="context" />.
        /// </summary>
        /// <param name="context">The <see cref="ITypeActivationContext" /> instance that describes the object to be created.</param>
        /// <returns>A method activator.</returns>
        public static ITypeActivator GetActivator(ITypeActivationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // Use the static activator by default
            var currentActivator = _activator;

            // Use the activator attached to the target if it exists
            var host = context.Target as IActivatorHost;

            if (host != null && host.Activator != null)
            {
                currentActivator = host.Activator;
            }

            if (currentActivator != null && currentActivator.CanActivate(context))
            {
                return(currentActivator);
            }

            return(null);
        }
        public object CreateInstance(ITypeActivationContext context)
        {
            var targetType = context.TargetType;

            // HACK: We need to manually map the FamilyCarEngine back to
            // an Engine type since there's currently no way to automatically
            // figure out the correct service that should be
            // instantiated from the container
            var serviceType = targetType;

            if (serviceType == typeof(FamilyCarEngine))
                serviceType = typeof(Engine);

            var result = _locator.GetInstance(serviceType);

            return result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Obtains an activator for the given <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="ITypeActivationContext"/> instance that describes the object to be created.</param>
        /// <returns>A method activator.</returns>
        public static ITypeActivator GetActivator(ITypeActivationContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            // Use the static activator by default
            var currentActivator = _activator;

            // Use the activator attached to the target if it exists
            var host = context.Target as IActivatorHost;
            if (host != null && host.Activator != null)
                currentActivator = host.Activator;

            if (currentActivator != null && currentActivator.CanActivate(context))
                return currentActivator;

            return null;
        }
Exemplo n.º 4
0
        public object CreateInstance(ITypeActivationContext context)
        {
            var targetType = context.TargetType;

            // HACK: We need to manually map the FamilyCarEngine back to
            // an Engine type since there's currently no way to automatically
            // figure out the correct service that should be
            // instantiated from the container
            var serviceType = targetType;

            if (serviceType == typeof(FamilyCarEngine))
            {
                serviceType = typeof(Engine);
            }

            var result = _locator.GetInstance(serviceType);

            return(result);
        }
Exemplo n.º 5
0
 public object CreateInstance(ITypeActivationContext context)
 {
     return _createInstance(context);
 }
Exemplo n.º 6
0
 public bool CanActivate(ITypeActivationContext context)
 {
     return true;
 }
Exemplo n.º 7
0
 public object CreateInstance(ITypeActivationContext context)
 {
     return(_createInstance(context));
 }
Exemplo n.º 8
0
 public bool CanActivate(ITypeActivationContext context)
 {
     return(true);
 }
Exemplo n.º 9
0
 public bool CanActivate(ITypeActivationContext context)
 {
     return(CreateInstance(context) != null);
 }
 public bool CanActivate(ITypeActivationContext context)
 {
     return CreateInstance(context) != null;
 }