Я пытаюсь реализовать следующую ситуацию:
Импорт:
private IEnumerable<ExportFactory<IPage, IPageMetadata>> _pageFactories = null;
[ImportMany("Page", typeof(IPage), AllowRecomposition = true)]
public IEnumerable<ExportFactory<IPage, IPageMetadata>> PageFactories
{
get { return _pageFactories; }
set { _pageFactories = value; }
}
Экспорт:
[PartCreationPolicy(CreationPolicy.NonShared)]
[ExportPage(ModuleNames.Kiosk, "/Kiosk/CreateProject", typeof(IPage))]
public partial class ProjectView : IPage
{
}
Атрибут экспорта:
public interface IPageMetadata
{
String ModuleName { get; }
String Version { get; }
String RelativeUri { get; }
}
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
public class ExportPageAttribute : ExportAttribute
{
private String _strModuleName = "";
private String _strVersion = "0.0";
private String _strRelativeUri = "";
public ExportPageAttribute(String a_strModuleName, String a_strRelativeUri)
: base("Page")
{
_strRelativeUri = a_strRelativeUri;
_strModuleName = a_strModuleName;
}
public ExportPageAttribute(String a_strModuleName, String a_strRelativeUri, Type a_contractType)
: base("Page", a_contractType)
{
_strRelativeUri = a_strRelativeUri;
_strModuleName = a_strModuleName;
}
public String RelativeUri
{
get { return _strRelativeUri; }
private set { _strRelativeUri = value; }
}
public String ModuleName
{
get { return _strModuleName; }
private set { _strModuleName = value; }
}
public String Version
{
get { return _strVersion; }
set { _strVersion = value; }
}
}
Создание контейнера:
AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
AggregateCatalog aggregateCatalog = new AggregateCatalog(assemblyCatalog);
CompositionContainer compositionContainer = new CompositionContainer(aggregateCatalog);
CompositionHost.Initialize(compositionContainer);
Когда вызывается PageFactories_set
(что это такое), предоставленная последовательность пуста.Следующее работает, хотя:
private IPage[] _pages;
[ImportMany("Page", typeof(IPage), AllowRecomposition = true)]
public IPage[] Pages
{
get { return _pages; }
set { _pages = value; }
}