开发者

How do I set the generic parameter to only specific type parameters in this Windsor installer using the fluent API?

I currently have this installer:

class DemiInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, 
        IConfigurationStore store)
    {
        List<Type> types = new List<Type>
        {
            typeof(ServicePlan),
            typeof(AccountGetService开发者_StackOverflow中文版),
            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)));
        }
    }
}

Instead of iterating over the list is there a function in the Windsor's Fluent API that implements this kind of behaviour?

Can I do other kinds of filtering based on the generic type?


Just register

container.Register(Component.For(typeof(IRepository<>)).ImplementedBy(typeof(ARRepository<>)));


container.Register(AllTypes.FromThisAssembly()
                            .BasedOn(typeof(IRepository<>))
                            .WithService.FromInterface());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜