/
DefaultConventionScanner.cs
36 lines (33 loc) · 1.11 KB
/
DefaultConventionScanner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Linq;
using System.Reflection;
using StructureMap.Configuration.DSL;
using StructureMap.Graph.Scanning;
using StructureMap.TypeRules;
namespace StructureMap.Graph
{
public class DefaultConventionScanner : ConfigurableRegistrationConvention
{
public override void ScanTypes(TypeSet types, Registry registry)
{
types.FindTypes(TypeClassification.Concretes).Where(type => type.HasConstructors()).Each(type =>
{
var pluginType = FindPluginType(type);
if (pluginType != null)
{
registry.AddType(pluginType, type);
ConfigureFamily(registry.For(pluginType));
}
});
}
public virtual Type FindPluginType(Type concreteType)
{
var interfaceName = "I" + concreteType.Name;
return concreteType.GetInterfaces().FirstOrDefault(t => t.Name == interfaceName);
}
public override string ToString()
{
return "Default I[Name]/[Name] registration convention";
}
}
}