private static void SatisfyImportsInternal(this CompositionContext exportProvider, object objectWithLooseImports, AttributedModelProvider conventions) { if (exportProvider == null) throw new ArgumentNullException("exportProvider"); if (objectWithLooseImports == null) throw new ArgumentNullException("objectWithLooseImports"); if (conventions == null) throw new ArgumentNullException("conventions"); var objType = objectWithLooseImports.GetType(); foreach (var pi in objType.GetRuntimeProperties()) { ImportInfo importInfo; var site = new PropertyImportSite(pi); if (ContractHelpers.TryGetExplicitImportInfo(pi.PropertyType, conventions.GetDeclaredAttributes(pi.DeclaringType, pi), site, out importInfo)) { object value; if (exportProvider.TryGetExport(importInfo.Contract, out value)) { pi.SetValue(objectWithLooseImports, value); } else if (!importInfo.AllowDefault) { throw new CompositionFailedException(string.Format( Properties.Resources.CompositionContextExtensions_MissingDependency, pi.Name, objectWithLooseImports)); } } } var importsSatisfiedMethods = objectWithLooseImports.GetType().GetRuntimeMethods().Where(m => m.CustomAttributes.Any(ca => ca.AttributeType == typeof(OnImportsSatisfiedAttribute))); foreach (var ois in importsSatisfiedMethods) ois.Invoke(objectWithLooseImports, null); }