コード例 #1
0
 /// <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>
 /// <param name="factory">Factory implementation for the service.</param>
 /// <returns>True if the registration was successful, false otherwise.</returns>
 public static bool TryAdd <TService>(this IServiceCollectionExtender services, Func <IServiceProvider, TService> factory)
 => services.TryAdd <TService>(factory, out _);
コード例 #2
0
 /// <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>
 /// <param name="factory">Factory implementation for the service.</param>
 /// <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>(this IServiceCollectionExtender services, Func <IServiceProvider, TService> factory, out ServiceExtensionResult result)
 => services.TryAdd(typeof(TService), ExposedImplementation.FromFactory(factory), out result);
コード例 #3
0
 /// <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>
 /// <returns>True if the registration was successful, false otherwise.</returns>
 public static bool TryAdd <TService, TImplementation>(this IServiceCollectionExtender services) where TImplementation : class, TService
 => services.TryAdd <TService, TImplementation>(out _);
コード例 #4
0
 /// <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);