Exemplo n.º 1
0
 private void InstantiateInterface(ContainerService.Builder builder)
 {
     HashSet<ImplementationType> implementationTypes;
     try
     {
         implementationTypes = GetImplementationTypes(builder);
     }
     catch (Exception e)
     {
         builder.SetError(e);
         return;
     }
     ApplySelectors(implementationTypes, builder);
     if (implementationTypes.Count == 0)
     {
         builder.SetComment("has no implementations");
         return;
     }
     Func<object> factory = null;
     var canUseFactory = true;
     foreach (var implementationType in implementationTypes)
         if (implementationType.accepted)
         {
             var implementationService = ResolveCore(ServiceName.Parse(implementationType.type, InternalHelpers.emptyStrings),
                 builder.CreateNew, builder.Arguments, builder.Context);
             builder.LinkTo(containerContext, implementationService, implementationType.comment);
             if (builder.CreateNew && builder.Arguments == null &&
                 implementationService.Status == ServiceStatus.Ok && canUseFactory)
                 if (factory == null)
                 {
                     if (!factoryCache.TryGetValue(implementationService.Name, out factory))
                         canUseFactory = false;
                 }
                 else
                     canUseFactory = false;
             if (builder.Status.IsBad())
                 return;
         }
         else
         {
             var dependency = containerContext.NotResolved(null, implementationType.type.FormatName());
             dependency.Comment = implementationType.comment;
             builder.AddDependency(dependency, true);
         }
     builder.EndResolveDependencies();
     if (factory != null && canUseFactory)
         factoryCache.TryAdd(builder.GetFinalName(), factory);
 }
Exemplo n.º 2
0
 private void InstantiateInterface(ContainerService.Builder builder)
 {
     var implementationTypes = GetImplementationTypes(builder);
     ApplySelectors(implementationTypes, builder);
     if (implementationTypes.Count == 0)
     {
         builder.SetComment("has no implementations");
         return;
     }
     Func<object> factory = null;
     var canUseFactory = true;
     foreach (var implementationType in implementationTypes)
         if (implementationType.accepted)
         {
             var implementationService = builder.CreateNew
                 ? builder.Context.Instantiate(implementationType.type, true, builder.Arguments)
                 : builder.Context.Resolve(ServiceName.Parse(implementationType.type, false));
             builder.LinkTo(containerContext, implementationService, implementationType.comment);
             if (builder.CreateNew && builder.Arguments == null &&
                 implementationService.Status == ServiceStatus.Ok && canUseFactory)
                 if (factory == null)
                 {
                     if (!factoryCache.TryGetValue(implementationService.Name, out factory))
                         canUseFactory = false;
                 }
                 else
                     canUseFactory = false;
             if (builder.Status.IsBad())
                 return;
         }
         else
         {
             var dependency = ServiceDependency.NotResolved(null, implementationType.type.FormatName());
             dependency.Comment = implementationType.comment;
             builder.AddDependency(dependency, true);
         }
     builder.EndResolveDependencies();
     if (factory != null && canUseFactory)
         factoryCache.TryAdd(builder.GetName(), factory);
 }