/// <summary> /// Causes the container to instantiate the service with the given /// <paramref name="serviceType">service type</paramref>. If the service type cannot be created, then an /// exception will be thrown if the <see cref="IContainer.SuppressErrors" /> property /// is set to false. Otherwise, it will simply return null. /// </summary> /// <param name="serviceName">The name of the service to instantiate.</param> /// <param name="serviceType">The service type to instantiate.</param> /// <param name="additionalArguments">The additional arguments that will be used to instantiate the service type.</param> /// <returns> /// If successful, it will return a service instance that is compatible with the given type; /// otherwise, it will just return a <c>null</c> value. /// </returns> public virtual object GetService(string serviceName, Type serviceType, params object[] additionalArguments) { IFactory factory = null; if (FactoryStorage != null) { factory = FactoryStorage.GetFactory(serviceName, serviceType, additionalArguments); } var serviceRequest = new ServiceRequest(serviceName, serviceType, additionalArguments, factory, this); var instance = _getServiceBehavior.GetService(serviceRequest); if (SuppressErrors == false && instance == null && serviceName == null) { throw new ServiceNotFoundException(serviceType); } if (SuppressErrors == false && instance == null && serviceName != null) { throw new NamedServiceNotFoundException(serviceName, serviceType); } return(instance); }
/// <summary> /// Adds an <see cref="IFactory" /> instance and associates it /// with the given <paramref name="serviceType">service type</paramref> and /// <paramref name="serviceName">service name</paramref>. /// </summary> /// <param name="serviceName">The name of the service to associate with the given <see cref="IFactory" /> instance.</param> /// <param name="serviceType">The type of service that the factory will be able to create.</param> /// <param name="additionalParameterTypes">The list of additional parameters that this factory type will support.</param> /// <param name="factory">The <see cref="IFactory" /> instance that will create the object instance.</param> public virtual void AddFactory(string serviceName, Type serviceType, IEnumerable <Type> additionalParameterTypes, IFactory factory) { FactoryStorage.AddFactory(serviceName, serviceType, additionalParameterTypes, factory); }
/// <summary> /// Determines whether or not a service can be created using /// the given <paramref name="serviceName">service name</paramref> /// and <paramref name="serviceType">service type</paramref>. /// </summary> /// <param name="serviceName">The name of the service to associate with the given <see cref="IFactory" /> instance.</param> /// <param name="serviceType">The type of service that the factory will be able to create.</param> /// <param name="additionalParameterTypes">The list of additional parameters that this factory type will support.</param> /// <returns>Returns <c>true</c> if the service exists; otherwise, it will return <c>false</c>.</returns> public virtual bool Contains(string serviceName, Type serviceType, IEnumerable <Type> additionalParameterTypes) { return(FactoryStorage.ContainsFactory(serviceName, serviceType, additionalParameterTypes)); }