简体   繁体   中英

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),
            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?

只需注册

container.Register(Component.For(typeof(IRepository<>)).ImplementedBy(typeof(ARRepository<>)));
container.Register(AllTypes.FromThisAssembly()
                            .BasedOn(typeof(IRepository<>))
                            .WithService.FromInterface());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM