我正在做的一个项目使用 StructureMap。我们有一个使用这样的代码段:
Scan(x =>
{
try
{
x.Convention<SqlTypesConvention>();
x.Assembly("ASSEMBLY NAME HERE");
}
catch
{
}
});
internal class SqlTypesConvention : IRegistrationConvention
{
#region IRegistrationConvention Members
public void Process(Type type, Registry registry)
{
string interfaceName = "I" + type.Name + "Data";
Type interfaceType = type.GetInterface(interfaceName);
if (type.IsAbstract || !type.IsClass || interfaceType.IsNullRef())
{
return;
}
registry.AddType(interfaceType, type);
}
#endregion IRegistrationConvention Members
}
这个扫描和约定代码有什么作用?