Exemple #1
0
 private ComponentRegistration <T> WithLifespan <T>(
     ComponentRegistration <T> componentRegistration,
     Lifespan lifespan)
     where T : class
 {
     if (lifespan == Lifespan.Singleton)
     {
         return(componentRegistration.LifestyleSingleton());
     }
     else if (lifespan == Lifespan.Transient)
     {
         return(componentRegistration.LifeStyle.Transient);
     }
     else if (lifespan is Lifespan.LifespanTypeBound typeBound)
     {
         var method        = componentRegistration.GetType().GetMethod("LifestyleBoundTo", new Type[] { });
         var genericMethod = method.MakeGenericMethod(typeBound.BoundType);
         return((ComponentRegistration <T>)genericMethod.Invoke(
                    componentRegistration, new object[0]));
     }
     else
     {
         throw new ArgumentException("invalid lifespan");
     }
 }
        IEnumerable <Type> GetServices(ComponentRegistration r)
        {
            var bf       = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public;
            var property = r.GetType().GetProperties(bf).Single(p => p.Name == "Services");
            var types    = property.GetValue(r, null) as IEnumerable <Type>;

            return(types);
        }
        IEnumerable<Type> GetServices( ComponentRegistration r ) 
        {
            var bf = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public;
            var property = r.GetType().GetProperties( bf ).Single( p => p.Name == "Services" );
            var types = property.GetValue( r, null ) as IEnumerable<Type>;

            return types;
        }