private void ProcessFields(IConfigurableActivationStrategy strategy) { foreach (var fieldInfo in strategy.ActivationType.GetRuntimeFields()) { if (!fieldInfo.IsPublic || fieldInfo.IsStatic) { continue; } foreach (var attribute in fieldInfo.GetCustomAttributes()) { var importAttr = attribute as IImportAttribute; var importInfo = importAttr?.ProvideImportInfo(strategy.ActivationType, fieldInfo.Name); if (importInfo != null) { var name = fieldInfo.Name; strategy.MemberInjectionSelector(new PropertyFieldInjectionSelector(fieldInfo.FieldType, info => info.Name == name, false) { IsRequired = importInfo.IsRequired, LocateKey = importInfo.ImportKey }); } } } }
private void ProcessProperties(IConfigurableActivationStrategy strategy) { foreach (var propertyInfo in strategy.ActivationType.GetRuntimeProperties()) { if (!propertyInfo.CanWrite || !propertyInfo.SetMethod.IsPublic || propertyInfo.SetMethod.IsStatic) { continue; } foreach (var attribute in propertyInfo.GetCustomAttributes()) { var importAttr = attribute as IImportAttribute; var importInfo = importAttr?.ProvideImportInfo(strategy.ActivationType, propertyInfo.Name); if (importInfo != null) { var name = propertyInfo.Name; strategy.MemberInjectionSelector(new PropertyFieldInjectionSelector(propertyInfo.PropertyType, m => m.Name == name, false) { IsRequired = importInfo.IsRequired, LocateKey = importInfo.ImportKey }); } } } }
/// <summary> /// Import a specific member /// </summary> /// <param name="selector">selector method, can be null</param> /// <param name="injectMethods"></param> /// <returns>configuraiton object</returns> public IFluentExportStrategyConfiguration ImportMembers(Func <MemberInfo, bool> selector = null, bool injectMethods = false) { _exportConfiguration.MemberInjectionSelector(new PublicMemeberInjectionSelector(selector, injectMethods)); return(this); }