Ejemplo n.º 1
0
        public void AddComponent(Type service, Type implementation, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Transient, params Parameter[] parameters)
        {
            SupportabilityCheck.CheckParameters(parameters);

            if (service.IsGenericTypeDefinition)
            {
                throw new NotSupportedFeaturesException();
            }
            else
            {
                registerTypes.AddRange(new[] { implementation });

                PartBuilder pb = null;

                pb = builder.ForType(implementation);
                if (string.IsNullOrEmpty(key))
                {
                    pb = pb.Export(it => it.AsContractType(service));
                }
                else
                {
                    pb = pb.Export(it => it.AsContractType(service).AsContractName(key));
                }
                pb = pb.SelectConstructor(ctors =>
                                          ctors.MinBy(it => it.GetParameters().Length));

                pb = pb.LifeStyle(lifeStyle);
            }
        }
Ejemplo n.º 2
0
 public T TryResolve <T>(string key = "", params Parameter[] parameters)
 {
     SupportabilityCheck.CheckParameters(parameters);
     return(Container.GetExportedValueOrDefault <T>(key));
 }
Ejemplo n.º 3
0
 public object TryResolve(Type type, string key = "", params Parameter[] parameters)
 {
     SupportabilityCheck.CheckParameters(parameters);
     return(Container.GetExportedValueOrDefault(type, key));
 }
Ejemplo n.º 4
0
        public T Resolve <T>(string key = "", params Parameter[] parameters) where T : class
        {
            SupportabilityCheck.CheckParameters(parameters);

            return(Container.GetExportedValue <T>(key));
        }