/// <summary> /// Activate value /// </summary> /// <param name="exportInjectionScope">injection scope</param> /// <param name="context">injection context</param> /// <param name="consider">consider filter</param> /// <param name="locateKey"></param> /// <returns>activated value</returns> public object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { string parameterName = ParameterName; if (context.TargetInfo == null) { throw new Exception("Must be injecting into type"); } if (string.IsNullOrEmpty(parameterName)) { parameterName = context.TargetInfo.InjectionTargetName; } string propertyString = HttpContext.Current.Request.QueryString[parameterName]; if (context.TargetInfo.InjectionTargetType != typeof(string) && !string.IsNullOrEmpty(propertyString)) { Type underlyingType = Nullable.GetUnderlyingType(context.TargetInfo.InjectionTargetType); if (underlyingType != null) { return Convert.ChangeType(propertyString, underlyingType); } if (context.TargetInfo.InjectionTargetType.IsValueType) { return Convert.ChangeType(propertyString, context.TargetInfo.InjectionTargetType); } throw new ArgumentException("You can only import ValueTypes or Nullable Types"); } return propertyString; }
/// <summary> /// Can locate a type /// </summary> /// <param name="context"></param> /// <param name="resolveName"></param> /// <param name="resolveType"></param> /// <param name="consider"></param> /// <param name="locateKey"></param> /// <returns></returns> public bool CanLocate(IInjectionContext context, string resolveName, Type resolveType, ExportStrategyFilter consider, object locateKey) { if (resolveType != null && resolveType.IsInterface) { return true; } return false; }
/// <summary> /// activate the strategy /// </summary> /// <param name="exportInjectionScope">injection scope</param> /// <param name="context">injection context</param> /// <param name="consider">consider filter</param> /// <param name="locateKey"></param> /// <returns>activated object</returns> public override object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { if (_lifestyle != null) { return _lifestyle.Locate(InternalActivate, exportInjectionScope, context, this); } return InternalActivate(exportInjectionScope, context); }
public object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { if (HttpContext.Current != null) { return HttpContext.Current.Request.Path; } return null; }
/// <summary> /// Activate the export /// </summary> /// <param name="exportInjectionScope"></param> /// <param name="context"></param> /// <param name="consider"></param> /// <param name="locateKey"></param> /// <returns></returns> public override object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { object targetOject = strategy.Activate(exportInjectionScope, context, consider, locateKey); if (targetOject != null) { return propertyAccessor(targetOject); } return null; }
/// <summary> /// ResolveAll will be called every time a collection is resolved /// </summary> /// <param name="owningScope"></param> /// <param name="context"></param> /// <param name="resolveName"></param> /// <param name="resolveType"></param> /// <param name="collectionEmpty"></param> /// <param name="consider"></param> /// <param name="locateKey"></param> /// <returns></returns> public IEnumerable<object> LocateAll(IInjectionScope owningScope, IInjectionContext context, string resolveName, Type resolveType, bool collectionEmpty, ExportStrategyFilter consider, object locateKey) { if (resolveType != null && resolveType.IsInterface && collectionEmpty) { Type createType = typeof(NSubstituteExportStrategy<>).MakeGenericType(resolveType); ICompiledExportStrategy newStrategy = Activator.CreateInstance(createType) as ICompiledExportStrategy; if (newStrategy != null) { newStrategy.SetLifestyleContainer(new SingletonLifestyle()); newStrategy.AddExportType(resolveType); owningScope.AddStrategy(newStrategy); yield return newStrategy.Activate(owningScope, context, null, locateKey); } } }
/// <summary> /// Activate the export /// </summary> /// <param name="exportInjectionScope"></param> /// <param name="context"></param> /// <param name="consider"></param> /// <param name="locateKey"></param> /// <returns></returns> public override object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { if (Log.IsDebugEnabled) { if (Lifestyle != null) { Log.DebugFormat("Activating export type {0} with life cycle container {1} ", ActivationType.FullName, Lifestyle.GetType().FullName); } else { Log.DebugFormat("Activating export type {0} with no life cycle container ", ActivationType.FullName); } } try { if (_lifestyle != null) { return _lifestyle.Locate(activationDelegate, exportInjectionScope, context, this); } return activationDelegate(exportInjectionScope, context); } catch (LocateException locateException) { locateException.AddLocationInformationEntry(new StrategyBeingActivated(this)); throw; } catch (Exception exp) { GeneralLocateException locateException = new GeneralLocateException(null, (Type)null, context, exp); locateException.AddLocationInformationEntry(new StrategyBeingActivated(this)); throw locateException; } }
public ParameterExpression GetLocateDependencyExpression(Type importType = null, string importName = null, IInjectionTargetInfo targetInfo = null, string variableName = null, bool isRequired = true, IExportValueProvider valueProvider = null, ExportStrategyFilter exportStrategyFilter = null, ILocateKeyValueProvider locateKey = null, object comparerObject = null) { if (importType == null && importName == null) { throw new ArgumentException("GetLocateDependencyExpression must be called with importType or "); } return null; }
/// <summary> /// Activate the export /// </summary> /// <param name="exportInjectionScope"></param> /// <param name="context"></param> /// <param name="consider"></param> /// <param name="locateKey"></param> /// <returns></returns> public override object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { throw new Exception("You can't activate a generic type. The type must be closed into an compiled instance export."); }
/// <summary> /// Activate the export /// </summary> /// <param name="exportInjectionScope">injection scope that is activating this strategy (not always owning)</param> /// <param name="context">injection context</param> /// <param name="consider">export filter</param> /// <param name="locateKey">locate key</param> /// <returns>activated object</returns> public abstract object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey);
public object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { return activationDelegate(); }
/// <summary> /// Cannot activate this strategy, you must create a closed strategy /// </summary> /// <param name="exportInjectionScope"></param> /// <param name="context"></param> /// <param name="consider"></param> /// <param name="locateKey"></param> /// <returns></returns> public override object Activate(IInjectionScope exportInjectionScope, IInjectionContext context, ExportStrategyFilter consider, object locateKey) { throw new NotImplementedException(); }