I would like to just use RegistrationBuilder to create parts.
example:
because when i use RegistrationBuilder the all type when wrapped in ProjectingType,but GetExportedValue method did not wrap Generic Parameters in ProjectingType.
My temporary solution is to modify the ImportDefinition.Metadata to make sure the Generic Parameters wrapped in ProjectingType.
is there any good solution or correction?
example:
public interface IModel
{
String Name { get; }
}
public interface IRepository
{
}
class ModelOne : IModel
{
public String Name { get { return "ModelOne"; } }
}
class ModelTwo : IModel
{
public String Name { get { return "ModelTwo"; } }
}
public interface IRepository<TModel> : IRepository where TModel : IModel
{
IContext<TModel> Context { get; set; }
}
public class Repository<TModel> : IRepository<TModel> where TModel : IModel
{
}
static void Main(String[] args)
{
var builder = new RegistrationBuilder();
builder.ForTypesDerivedFrom<IModel>()
.Export()
.Export<IModel>();
builder.ForTypesDerivedFrom<IRepository>()
.ExportInterfaces();
var asmCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly(), builder);
var container = new CompositionContainer(asmCatalog);
var one = container.GetExportedValue<IRepository<ModelOne>>();
var two = container.GetExportedValue<IRepository<ModelTwo>>();
}
I can not get the results(the one,the two) I want。
because when i use RegistrationBuilder the all type when wrapped in ProjectingType,but GetExportedValue method did not wrap Generic Parameters in ProjectingType.
My temporary solution is to modify the ImportDefinition.Metadata to make sure the Generic Parameters wrapped in ProjectingType.
is there any good solution or correction?