我正在写一个小插件体系结构,我决定使用MEF 我被告知必须使用配置文件。简单的插件与MEF。我可以使用配置文件加载插件文件
是否有任何使用Mef和配置文件的例子?
我需要的是如何在配置文件中设置mef是可能的吗?这是一个小诺迪的例子,我已经建立,以测试它,我错过了loadPlugin功能和配置文件,您可以帮助
诺迪例如
//MyCompany.Payment.Contracts.dll
public interface IPayment
{
bool Pay();
}
//MyCompany.Payment.ServiceProviderOne.dll
[Export(typeof(IPayment))]
public class ServiceProviderOne:IPayment
{
public bool Pay(return true);
}
//MyCompany.Payment.ServiceProviderTwo.dll
[Export(typeof(IPayment))]
public class ServiceProviderTwo:IPayment
{
?public bool Pay(return true);
}
//Main Console.Applicaiton
class Program
{
static void Main(string[] args)
{
HelperPlugin helperPlugin =new HelperPlugin();
List<IPayment> myLoadedPayments= helperPlugin.GetPlugins();
//blahhh conti
}
}
public cass HelperPlugin
{
[ImportMany(typeof(IPayment))]
public List<IPayment>Payments { get; set; }
public List<IPayment>GetPlugins()
{
Payments=new List<IPayment>();
LoadPlugins();
return Payments;
}
private void LoadPlugins()
{
???
}
}
配置文件是什么样子的?
感谢您的任何建议或代码片段