0
是否可以使用MEF來組成WCF RIA域服務?MEF - 如何撰寫WCF RIA DomainService?
比方說,我有以下域服務屬性:
[Import(RequiredCreationPolicy = CreationPolicy.Shared)]
public TestClass Dependency{ get; set; }
而且TestClass中..
[Export]
public class TestClass
{
public void Do()
{
}
}
而且我有一個DomainServiceFactory類:
public class DomainServiceFactory : IDomainServiceFactory
{
private readonly ComposablePartCatalog _catalog;
private readonly CompositionContainer _container;
public DomainServiceFactory()
{
_catalog = new TypeCatalog(typeof(DomainService1), typeof(DomainService2));
_container = new CompositionContainer(_catalog);
//What should I call here? _container.SatisfyImportsOnce(this);
}
#region Implementation of IDomainServiceFactory
public DomainService CreateDomainService(Type domainServiceType, DomainServiceContext context)
{
DomainService domainService;
var export = _container.GetExports(domainServiceType, null, null).FirstOrDefault();
if(export != null)
{
domainService = (DomainService) export.Value;
}
else
{
domainService = (DomainService)Activator.CreateInstance(domainServiceType);
}
domainService.Initialize(context);
return domainService;
}
public void ReleaseDomainService(DomainService domainService)
{
domainService.Dispose();
}
#endregion
}
是否SatisfyImportsOnce構建容器的方法?輸入參數是一個ComposablePart,我應該傳入什麼?
問候。
當調用GetExports(...)時,我得到空。這就是爲什麼我認爲它沒有初始化。 – Alberto 2012-07-27 17:34:14
您是否已經使用特定合約導出了您的類型I.e [Export(typeof(DomainService))]還是僅[Export]? – 2012-07-27 17:49:09
只需[導出]。星期一將嘗試[導出(typeof(DomainService))]。沒有意識到。 – Alberto 2012-07-27 17:52:06