private void ProcessClassAttributes(IConfigurableActivationStrategy strategy) { foreach (var attribute in strategy.ActivationType.GetTypeInfo().GetCustomAttributes()) { var exportAttribute = attribute as IExportAttribute; var types = exportAttribute?.ProvideExportTypes(strategy.ActivationType); if (types != null) { foreach (var type in types) { strategy.AddExportAs(type); } } var conditionAttribute = attribute as IExportConditionAttribute; var condition = conditionAttribute?.ProvideCondition(strategy.ActivationType); if (condition != null) { strategy.AddCondition(condition); } var keyedTypeAttribute = attribute as IExportKeyedTypeAttribute; var tuple = keyedTypeAttribute?.ProvideKey(strategy.ActivationType); if (tuple != null) { strategy.AddExportAsKeyed(tuple.Item1, tuple.Item2); } } }
/// <summary> /// Export as keyed interface /// </summary> /// <param name="type">type to export as</param> /// <param name="key">key to export under</param> /// <returns></returns> public IFluentExportStrategyConfiguration AsKeyed(Type type, object key) { if (type == null) throw new ArgumentNullException(nameof(type)); if (key == null) throw new ArgumentNullException(nameof(key)); _exportConfiguration.AddExportAsKeyed(type, key); return this; }
/// <summary> /// Export as keyed interface /// </summary> /// <param name="type">type to export as</param> /// <param name="key">key to export under</param> /// <returns></returns> public IFluentExportStrategyConfiguration AsKeyed(Type type, object key) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } if (type.GetTypeInfo().IsGenericTypeDefinition&& !_exportConfiguration.ActivationType.GetTypeInfo().IsGenericTypeDefinition) { throw new ArgumentException("Exported type is not open generic but As type is open"); } _exportConfiguration.AddExportAsKeyed(type, key); return(this); }
/// <summary> /// Export as keyed interface /// </summary> /// <param name="type">export type</param> /// <param name="key">export key</param> /// <returns></returns> public IFluentExportInstanceConfiguration <T> AsKeyed(Type type, object key) { _exportConfiguration.AddExportAsKeyed(type, key); return(this); }