Пример #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;
        }
Пример #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;
        }
Пример #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);
        }
Пример #5
0
 public object CreateInstance(ITypeActivationContext context)
 {
     return _createInstance(context);
 }
Пример #6
0
 public bool CanActivate(ITypeActivationContext context)
 {
     return true;
 }
Пример #7
0
 public object CreateInstance(ITypeActivationContext context)
 {
     return(_createInstance(context));
 }
Пример #8
0
 public bool CanActivate(ITypeActivationContext context)
 {
     return(true);
 }
Пример #9
0
 public bool CanActivate(ITypeActivationContext context)
 {
     return(CreateInstance(context) != null);
 }
 public bool CanActivate(ITypeActivationContext context)
 {
     return CreateInstance(context) != null;
 }