/// <summary> /// Adds a service implementation, raising an exception if any error occurs. /// </summary> /// <typeparam name="TService">Type of the service to be implemented.</typeparam> /// <typeparam name="TImplementation">Implementation type to register.</typeparam> /// <exception cref="InvalidOperationException">If the implementation cannot be registered.</exception> public static void Add <TService, TImplementation>(this IServiceCollectionExtender services) where TImplementation : class, TService => services.Add(typeof(TService), ExposedImplementation.FromType <TImplementation>());
/// <summary> /// Adds a service implementation, if either no implementations for said service was registered before or if multiple registrations are allowed by the host. /// </summary> /// <typeparam name="TService">Type of the service to be implemented.</typeparam> /// <typeparam name="TImplementation">Implementation type to register.</typeparam> /// <param name="result">Destination variable for the operation result.</param> /// <returns>True if the registration was successful, false otherwise.</returns> public static bool TryAdd <TService, TImplementation>(this IServiceCollectionExtender services, out ServiceExtensionResult result) where TImplementation : class, TService => services.TryAdd(typeof(TService), ExposedImplementation.FromType <TImplementation>(), out result);