0
작동하지 않는 경우의 ImportMany :ExportFactory의 나는 다음과 같은 상황을 구현하기 위해 노력하고
가져 오기 :
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; }
}