我参考了http://pwlodek.blogspot.in/2010/12/introduction-to-interceptingcatalog.html的资料
这是一个很好的例子,但我在使用这段代码时有点困惑。我正在创建一个WPF + Prism + MEF应用程序,在这里,我定义了所有依赖项,就像在"Stock“示例中定义的一样,我正在将所有模块初始化为MyBootstrapper类。在我的项目中,我有一个支持开放泛型的需求,就像上面的链接示例中提供的那样。现在我的问题是在哪里实现示例代码,我正在尝试将它实现为MyBootstrapper ConfigureAggregateCatalog()方法
[CLSCompliant(false)]
public partial class ImsBootstrapper : MefBootstrapper
{
protected override void ConfigureAggregateCatalog()
{
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (ImsBootstrapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (ImsCommands).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (DalModel).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (TestClass).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (TestClassImp).Assembly));
// Create source catalog
var typeCatalog = new TypeCatalog((typeof(RegistrationViewModel)));
// Create catalog which supports open-generics, pass in the registry
var genericCatalog = new GenericCatalog(new MyGenericContractRegistry());
// Aggregate both catalogs
var aggregateCatalog = new AggregateCatalog(typeCatalog, genericCatalog);
// Create the container
//var container = new CompositionContainer(aggregateCatalog);
this.Container = new CompositionContainer(aggregateCatalog);
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StudentModel).Assembly));
}但是它不起作用,请您指导我在哪里使用上面链接中给出的示例来获得开放泛型(:IRepository)支持
如果您仍然对我的问题感到困惑,只需给我一个例子,我如何在“股票交易RI”演示应用程序中获得OpenGeneric支持,使用"MefContrib“来实现这个目的,我正试图通过下面这个链接http://pwlodek.blogspot.in/2010/12/introduction-to-interceptingcatalog.html中的示例来实现这一点,但是在MyBootstrapper中如何调用该代码,或者其他代码在哪里被调用。
发布于 2012-06-11 10:11:08
您可以简单地使用.NET 4.5。在该版本中,对开放泛型的支持已经成为MEF的一部分,您不需要做任何特别的事情。见.NET框架4.5中什么是新的。
.NET 4.5尚未发布,但发布候选版本是已经可以在“现场直播”许可下使用。这意味着您可能已经在生产中使用它了。
编辑:如果不能使用.NET 4.5,仍然可以从mef.codeplex.com下载并使用最新的MEF2预览。例如,MEF2预览5支持开放的泛型,并将在.NET4上工作。
https://stackoverflow.com/questions/10976401
复制相似问题