/// <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; }
/// <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); }
public object CreateInstance(ITypeActivationContext context) { return _createInstance(context); }
public bool CanActivate(ITypeActivationContext context) { return true; }
public object CreateInstance(ITypeActivationContext context) { return(_createInstance(context)); }
public bool CanActivate(ITypeActivationContext context) { return(true); }
public bool CanActivate(ITypeActivationContext context) { return(CreateInstance(context) != null); }
public bool CanActivate(ITypeActivationContext context) { return CreateInstance(context) != null; }