/// <summary> /// Adds a service implemented by the given concrete type if no service for the given service /// type has already been registered. /// </summary> /// <param name="serviceType">The contract for the service.</param> /// <param name="implementationType">The concrete type that implements the service.</param> /// <param name="lifetime">The service lifetime.</param> /// <returns>The map, such that further calls can be chained.</returns> public virtual ServiceCollectionMap TryAdd( Type serviceType, Type implementationType, ServiceLifetime lifetime) { Validate?.Invoke(serviceType); var indexes = _map.GetOrCreateDescriptorIndexes(serviceType); if (indexes.Count == 0) { _map.AddNewDescriptor(indexes, new ServiceDescriptor(serviceType, implementationType, lifetime)); } return(this); }
/// <summary> /// Adds a service implemented by the given concrete type if no service for the given service /// type has already been registered. /// </summary> /// <param name="serviceType"> The contract for the service. </param> /// <param name="implementationType"> The concrete type that implements the service. </param> /// <param name="lifetime"> The service lifetime. </param> /// <returns> The map, such that further calls can be chained. </returns> public virtual ServiceCollectionMap TryAdd( [NotNull] Type serviceType, [NotNull] Type implementationType, ServiceLifetime lifetime) { Check.NotNull(serviceType, nameof(serviceType)); Check.NotNull(implementationType, nameof(implementationType)); var indexes = _map.GetOrCreateDescriptorIndexes(serviceType); if (indexes.Count == 0) { _map.AddNewDescriptor(indexes, new ServiceDescriptor(serviceType, implementationType, lifetime)); } return(this); }