Reputation: 1887
A project i am working on uses StructureMap. We have a code segment using something like this:
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
}
What does this Scan and Convention code do?
Upvotes: 0
Views: 876
Reputation: 6006
If there are any classes "XXX" that use the interface "IXXX" which starts with "I", then the structure map will scans for all the assembly for "xxxx" class and instantiates automatically. Detail information about how structure map works is available @ how structure map works
Upvotes: 1
Reputation: 6993
Frequently the interface for class Foo
is named IFoo
. Thus the convention is to prefix the class name with I
.
The convention in your code sample is that for a given class Foo
its interface will be named IFooData
StructureMap will use this convention to try to find the Interface relationships for all the Types. So, when a class constructor asks for an IFooData
StructureMap will be able to provide an instance of Foo
.
Upvotes: 2