有没有办法自动配置Automapper来扫描命名空间/程序集中的所有配置文件?我想做的是将映射配置文件从给定的程序集添加到由给定的接口过滤的AutoMapper中,类似于StructureMap中的扫描约定:
public static void Configure()
{
ObjectFactory.Initialize(x =>
{
// Scan Assembly
x.Scan(
scanner =>
{
scanner.TheCallingAssembly();
scanner.Convention<MyCustomConvention>();
scanner.WithDefaultConventions();
});
// Add Registries
x.AddRegistry(new SomeRegistry());
});
Debug.WriteLine(ObjectFactory.WhatDoIHave());
}
public class MyCustomConvention : IRegistrationConvention
{
public void Process(Type type, Registry registry)
{
if (!type.CanBeCastTo(typeof(IMyType)))
{
return;
}
string name = type.Name.Replace("SomeRubishName", String.Empty);
registry.AddType(typeof(IMyType), type, name);
}
我试过使用SelfConfigure,但找不到任何关于如何使用它来过滤配置文件的文档:
public static void Configure()
{
Mapper.Initialize(x =>
{
// My Custom profile
x.AddProfile<MyMappingProfile>();
// Scan Assembly
x.SelfConfigure(Assembly.GetCallingAssembly());
});
}
另一个问题是,我如何报告已经初始化的所有映射/配置文件(类似于StructureMap中的ObjectFactory.WhatDoIHave() )?
https://stackoverflow.com/questions/2651613
复制相似问题