Exemplo n.º 1
0
        private Lemming GetGenericLemmingFrom(ReferenceInjection injection, bool validate)
        {
            if (string.IsNullOrWhiteSpace(injection.ReferencedLemming))
            {
                return(GetGenericLemmingFrom(injection.Property.PropertyType, validate));
            }

            Lemming final;

            if (injection.IsGeneric)
            {
                var candidate =
                    genericLemmings.Single(
                        x =>
                        x.ConcreteType.GenericDefinitionInheritsFrom(injection.Property.PropertyType) &&
                        x.Name == injection.ReferencedLemming);
                final = candidate.MakeGenericLemming(injection.Property.PropertyType.GetGenericArguments());
            }
            else
            {
                var candidates = genericLemmings.Where(
                    x => x.ConcreteType.GenericDefinitionInheritsFrom(injection.Property.PropertyType))
                                 .Select(x => x.MakeGenericLemming(injection.Property.PropertyType.GetGenericArguments()));
                final = candidates.SingleOrDefault(x => x.UniqueName == injection.ReferencedLemming) ??
                        candidates.SingleOrDefault(x => x.Name == injection.ReferencedLemming);
            }

            if (final == null)
            {
                throw new NailsException(string.Format("There's no lemming defined for type {0} and name {1}",
                                                       injection.Property.PropertyType.FullFriendlyName(),
                                                       injection.ReferencedLemming));
            }

            var existing = addedGenericLemmings.SingleOrDefault(x => x.UniqueName == final.UniqueName);

            if (existing != null)
            {
                return(existing); //So, if it already exists we return that one instead of the new one.
            }
            addedGenericLemmings.Add(final);
            return(final);
        }
Exemplo n.º 2
0
            public void Inject(ReferenceInjection injection)
            {
                var value = new ReferenceResolver(objectFactory).GetReferenceFor(injection);

                propertiesCache[injection.Property].SetValue(instance, value);
            }
Exemplo n.º 3
0
 public void Inject(ReferenceInjection injection)
 {
     builder.AddPropertyReference(property, injection.ReferencedLemming);
 }
Exemplo n.º 4
0
            public void Inject(ReferenceInjection injection)
            {
                var value = new ReferenceResolver(objectFactory).GetReferenceFor(injection);

                injection.Property.SetValue(null, value, null);
            }