public override void Build(Container container)
        {
            var candidates = (from type in this.assemblies.Distinct().SelectMany(x => x.GetTypes())
                              let baseType = type.GetBaseTypesAndInterfaces().FirstOrDefault(x => x == this.ServiceType.Type || (x.IsGenericType && x.GetGenericTypeDefinition() == this.ServiceType.Type))
                                             where baseType != null
                                             select new { Type = type, Base = baseType.ContainsGenericParameters ? baseType.GetGenericTypeDefinition() : baseType }).ToList();

            if (!this.allowZeroImplementations && candidates.Count == 0)
            {
                throw new StyletIoCRegistrationException(String.Format("Did not find any implementations of the type {0}", this.ServiceType.Type));
            }

            foreach (var candidate in candidates)
            {
                try
                {
                    BuilderBindingBase.EnsureType(candidate.Type, candidate.Base);
                    this.BindImplementationToSpecificService(container, candidate.Type, candidate.Base, this.ServiceType.Key);
                }
                catch (StyletIoCRegistrationException e)
                {
                    Debug.WriteLine(String.Format("Unable to auto-bind type {0} to {1}: {2}", candidate.Base.Name, candidate.Type.GetDescription(), e.Message), "StyletIoC");
                }
            }
        }
        public IWithKeyOrAsWeakBindingOrDisposeWithContainer ToInstance(object instance)
        {
            var builderBinding = new BuilderInstanceBinding(this.ServiceTypes, instance);

            this.builderBinding = builderBinding;
            return(builderBinding);
        }
Beispiel #3
0
 public IInScopeOrWithKeyOrAsWeakBinding ToAllImplementations(IEnumerable <Assembly> assemblies)
 {
     this.builderBinding = new BuilderToAllImplementationsBinding(this.ServiceTypes, this.getAssemblies(assemblies, "ToAllImplementations"));
     return(this.builderBinding);
 }
Beispiel #4
0
 public IWithKeyOrAsWeakBinding ToAbstractFactory()
 {
     this.builderBinding = new BuilderAbstractFactoryBinding(this.ServiceTypes);
     return(this.builderBinding);
 }
Beispiel #5
0
 public IWithKeyOrAsWeakBinding ToInstance(object instance)
 {
     this.builderBinding = new BuilderInstanceBinding(this.ServiceTypes, instance);
     return(this.builderBinding);
 }
Beispiel #6
0
 public IInScopeOrWithKeyOrAsWeakBinding ToFactory <TImplementation>(Func <IRegistrationContext, TImplementation> factory)
 {
     this.builderBinding = new BuilderFactoryBinding <TImplementation>(this.ServiceTypes, factory);
     return(this.builderBinding);
 }
Beispiel #7
0
 public IInScopeOrWithKeyOrAsWeakBinding To(Type implementationType)
 {
     this.builderBinding = new BuilderTypeBinding(this.ServiceTypes, implementationType);
     return(this.builderBinding);
 }