public IService FindByClass(IServiceList list, Type @class)
 {
     return(list
            .GetServices()
            .Where(x => x.Registration.TargetType.IsAssignableFrom(@class))
            .FirstOrDefault());
 }
Пример #2
0
        public IEnumerable <IService> FindClasses(IServiceList list, Type @class)
        {
            IEnumerable <Type> keyParameters = GenericParametersProvider.ProvideGenericTypes(@class);

            return(list
                   .GetServices()
                   .Where(x => x.Registration.RegistrationFlags.Has(RegistrationFlagConstants.HasGenericParameters))
                   .Where(x => x.Registration.RegistrationFlags.SelectValueOrNull <IEnumerable <Type> >(RegistrationFlagConstants.GenericParameters).Count() == keyParameters.Count())
                   .Where(x => x.Registration.RegistrationFlags.SelectValueOrNull <IEnumerable <Type> >(RegistrationFlagConstants.GenericParameters).SequenceEqual(keyParameters)));
        }
Пример #3
0
        public IEnumerable <IService> FindManyByInterface(IServiceList list, Type @interface)
        {
            foreach (IService service in list.GetServices())
            {
                IEnumerable <IInterface> interfaces = InterfacesExtractor.ExtractInterfaces(service.Registration);

                IEnumerable <IInterface> matchingInterfaces = interfaces
                                                              .Where(x => !x.HasGenericArguments)
                                                              .Where(x => Comparer.Compare(@interface, x.Type));

                if (matchingInterfaces.Any())
                {
                    yield return(service);
                }
            }
        }
Пример #4
0
        public IEnumerable <IService> FindInterfaces(IServiceList list, Type @interface)
        {
            // return list.GetServices()
            //     .Where(x => x.Registration.Interfaces.Count > 0)
            //     .Where(x => x.Registration.Interfaces.Where(x => x.HasGenericArguments).Any())
            //     .Where(x => x.Registration.Interfaces.Where(x => Comparer.Compare(@interface, x.Type)).Any());


            // TODO provizory
            foreach (IService service in list.GetServices())
            {
                IEnumerable <IInterface> interfaces = InterfacesExtractor.ExtractInterfaces(service.Registration);

                IEnumerable <IInterface> matchingInterfaces = interfaces
                                                              .Where(x => x.HasGenericArguments)
                                                              .Where(x => Comparer.Compare(@interface, x.Type));

                if (matchingInterfaces.Any())
                {
                    yield return(service);
                }
            }
        }
 public IEnumerable <IService> FindManyByClass(IServiceList list, Type @class)
 {
     return(list
            .GetServices()
            .Where(x => x.Registration.TargetType.IsAssignableFrom(@class)));
 }
 public IEnumerable <IService> Filter(IServiceList list, IEnumerable <IService> services)
 {
     return(services.Where(x => list.GetServices().SingleOrDefault(y => y.Registration.TargetType == x.Registration.TargetType) == null));
 }