【发布时间】:2010-11-17 11:23:25
【问题描述】:
我目前有这个安装程序:
class DemiInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container,
IConfigurationStore store)
{
List<Type> types = new List<Type>
{
typeof(ServicePlan),
typeof(AccountGetService),
typeof(ServiceOrder),
typeof(WorkRosterHistory),
typeof(WorkRoster),
typeof(SmallHoursAmount),
typeof(Nurse),
typeof(ServicePlanHistory),
typeof(ServicePlanLine),
typeof(ServicePlanLineHistory),
typeof(AccountGetServiceAbsence),
typeof(NurseAbsence),
typeof(Holiday)
};
foreach (var type in types)
{
container.Register(
Component
.For(typeof(IRepository<>)
.MakeGenericType(type))
.ImplementedBy(typeof(ARRepository<>)
.MakeGenericType(type)));
}
}
}
Windsor 的 Fluent API 中是否有一个函数可以实现这种行为,而不是遍历列表?
我可以根据泛型类型进行其他类型的过滤吗?
【问题讨论】:
-
为什么?实际情况如何?你想达到什么目标?
-
@Krzysztof Koźmic:我试图只注册一些类型的存储库,因为我不需要全部。
-
@the_drow:如果你做注册所有这些会发生什么?这会容易得多,而且不会造成任何伤害。
-
@Mauricio Scheffer:我正在运行一些必须尽快初始化的东西,但我有需要解决的服务。
-
@the_drow:它会注册多少个存储库才能对性能产生重大影响?真正需要多长时间?你量过吗?
标签: c# .net castle-windsor ioc-container