/// <summary>
 /// Call this to build a service chain explicitly.
 /// Typically you just resolve the service with <see cref="IServiceProvider.GetService(Type)"/>, but
 /// in case you register your own factory of <typeparamref name="T"/>, you may need this to get the
 /// service chain registered with <see cref="IServiceCollection"/>.
 /// </summary>
 /// <typeparam name="T">The service type.</typeparam>
 /// <param name="obj">The <see cref="IServiceCollection"/>.</param>
 /// <returns>The service instance built.</returns>
 /// <example>
 /// <code>
 /// services.AddScoped &lt; ISomeService &gt;(sp =>
 ///     new SomeService(sp.BuildApiServiceChain &lt; ISomeService &gt;()));
 /// </code>
 /// </example>
 public static T BuildApiServiceChain <T>(this IServiceProvider obj) where T : class
 {
     Ensure.NotNull(obj, "obj");
     return(ChainedService <T> .DefaultFactory(obj));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Call this to build a service chain explicitly.
 /// Typically you just resolve the service with <see cref="IServiceProvider.GetService(Type)"/>, but
 /// in case you register your own factory of <typeparamref name="T"/>, you may need this to get the
 /// service chain registered with <see cref="IServiceCollection"/>.
 /// </summary>
 /// <typeparam name="T">The service type.</typeparam>
 /// <param name="services">The <see cref="IServiceCollection"/>.</param>
 /// <returns>The service instance built.</returns>
 /// <example>
 /// <code>
 /// services.AddScoped &lt; ISomeService &gt;(sp =>
 ///     new SomeService(sp.BuildApiServiceChain &lt; ISomeService &gt;()));
 /// </code>
 /// </example>
 public static T BuildApiServiceChain <T>(this IServiceProvider services) where T : class
 {
     Ensure.NotNull(services, "services");
     return(ChainedService <T> .DefaultFactory(services));
 }