//todo: very weirdly, after updating StructureMap to version 3, double dispatch via dynamic not works anymore(http://stackoverflow.com/questions/27011810/mystery-with-dynamic-type-double-dispatch)
        private static object ApplyResolver(GenericFamilyExpression builder, IImplementationResolver resolver)
        {
            if (resolver is StaticResolver)
            {
                return(builder.Add(((StaticResolver)resolver).Target));
            }
            if (resolver is InstanceResolver)
            {
                return(builder.Add(((InstanceResolver)resolver).Instance));
            }
            if (resolver is DynamicResolver)
            {
                return(builder.Add(c => ((DynamicResolver)resolver).FactoryFunc()));
            }

            Assumes.Fail("Unsupported IImplementationResolver implementation");
            return(null);
        }
示例#2
0
 private void addConcretionsThatCouldBeClosed(Type @interface, GenericFamilyExpression expression)
 {
     _concretions.Where(x => x.IsOpenGeneric())
     .Where(x => x.CouldCloseTo(@interface))
     .Each(type =>
     {
         try
         {
             expression.Add(
                 type.MakeGenericType(@interface.GetGenericArguments()));
         }
         catch (Exception)
         {
             // Because I'm too lazy to fight with the f*****g type constraints to "know"
             // if it's possible to make the generic type and this is just easier.
         }
     });
 }
 private static ObjectInstance ApplyResolver(GenericFamilyExpression builder, InstanceResolver resolver)
 {
     return builder.Add(resolver.Instance);
 }
 private static ConfiguredInstance ApplyResolver(GenericFamilyExpression builder, StaticResolver resolver)
 {
     return builder.Add(resolver.Target);
 }
 private static LambdaInstance<object> ApplyResolver(GenericFamilyExpression builder, DynamicResolver resolver)
 {
     return builder.Add(c => resolver.FactoryFunc());
 }