我可以在运行时使用 SimpleInjector 为泛型类型注册初始化程序吗?(见下面最后一行代码)
public class BootStrapper
{
Type baseTypeGeneric = typeof(Sample<>);
public void BootStrap(Container container)
{
var types =
from type in Assembly.GetExecutingAssembly().GetTypes()
where type.Namespace == "NS.xyz"
select type;
foreach (Type type in types)
{
Type baseType = baseTypeGeneric.MakeGenericType(type);
if (type.BaseType == baseType)
{
container.Register(type);
}
//how do I get this line to work?
container.RegisterInitializer<Sample<[type]>>(
x => container.InjectProperties(x));
}
}
}