src/packages/EmbedIO/WebApi/WebApiModuleBase.cs
/// <summary>
/// <para>Registers a controller type using a factory method.</para>
/// <para>In order for registration to be successful:</para>
/// <list type="bullet">
/// <item><description><paramref name="controllerType"/> must be a subclass of <see cref="WebApiController"/>;</description></item>
/// <item><description><paramref name="controllerType"/> must not be a generic type definition;</description></item>
/// <item><description><paramref name="factory"/>'s return type must be either <paramref name="controllerType"/>
/// or a subclass of <paramref name="controllerType"/>.</description></item>
/// </list>
/// </summary>
/// <param name="controllerType">The type of the controller.</param>
/// <param name="factory">The factory method used to construct instances of <paramref name="controllerType"/>.</param>
/// <exception cref="InvalidOperationException">The module's configuration is locked.</exception>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="controllerType"/> is <see langword="null"/>.</para>
/// <para>- or -</para>
/// <para><paramref name="factory"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// <para><paramref name="controllerType"/> is already registered in this module.</para>
/// <para>- or -</para>
/// <para>One or more parameters do not satisfy the prerequisites listed in the Summary section.</para>
/// </exception>
/// <remarks>
/// <para><paramref name="factory"/>will be called once for each request to handle
/// in order to obtain an instance of <paramref name="controllerType"/>.
/// The returned instance will be dereferenced immediately after handling the request.</para>
/// <para><paramref name="controllerType"/> is not required to be thread-safe,
/// as it will be constructed and used in the same synchronization context.
/// However, since request handling is asynchronous, the actual execution thread
/// may vary during execution. Care must be exercised when using thread-sensitive
/// resources or thread-static data.</para>
/// <para>If <paramref name="controllerType"/> implements <see cref="IDisposable"/>,
/// its <see cref="IDisposable.Dispose">Dispose</see> method will be called when it has
/// finished handling a request. In this case it is recommended that
/// <paramref name="factory"/> return a newly-constructed instance of <paramref name="controllerType"/>
/// at each invocation.</para>
/// <para>If <paramref name="controllerType"/> does not implement <see cref="IDisposable"/>,
/// <paramref name="factory"/> may employ techniques such as instance pooling to avoid
/// the overhead of constructing a new instance of <paramref name="controllerType"/>
/// at each invocation. If so, resources such as file handles, database connections, etc.
/// should be freed before returning from each handler method to avoid
/// <see href="https://en.wikipedia.org/wiki/Starvation_(computer_science)">starvation</see>.</para>
/// </remarks>
/// <seealso cref="RegisterControllerType(Type)"/>
/// <seealso cref="RegisterControllerType{TController}(Func{TController})"/>
Registers a controller type using a factory method.In order for registration to be successful: must be a subclass of ; must not be a generic type definition;'s return type must be either
or a subclass of .
Registers a controller type using a factory method . In order for registration to be successful : must be a subclass of ; must not be a generic type definition ; ' s return type must be either or a subclass of .
protected void RegisterControllerType(Type controllerType, Func<WebApiController> factory)
        {
            EnsureConfigurationNotLocked();
            controllerType = ValidateControllerType(nameof(controllerType), controllerType, true);
            factory = Validate.NotNull(nameof(factory), factory);
            if (!controllerType.IsAssignableFrom(factory.Method.ReturnType))
                throw new ArgumentException("Factory method has an incorrect return type.", nameof(factory));
            var expression = Expression.Call(
                factory.Target == null ? null : Expression.Constant(factory.Target),
                factory.Method);
            if (!TryRegisterControllerTypeCore(controllerType, expression))
                throw new ArgumentException($"Type {controllerType.Name} contains no controller methods.");
        }
protected void RegisterControllerType ( Type controllerType , Func < WebApiController > factory ) { EnsureConfigurationNotLocked ( ) ; controllerType = ValidateControllerType ( nameof ( controllerType ) , controllerType , true ) ; factory = Validate . NotNull ( nameof ( factory ) , factory ) ; if ( ! controllerType . IsAssignableFrom ( factory . Method . ReturnType ) ) throw new ArgumentException ( " " , nameof ( factory ) ) ; var expression = Expression . Call ( factory . Target == null ? null : Expression . Constant ( factory . Target ) , factory . Method ) ; if ( ! TryRegisterControllerTypeCore ( controllerType , expression ) ) throw new ArgumentException ( $" Type  { controllerType . Name }  contains no controller methods. " ) ; }
Registers a controller type using a factory method.In order for registration to be successful: must be a subclass of ; must not be a generic type definition;'s return type must be either
or a subclass of .
Registers a controller type using a factory method . In order for registration to be successful : must be a subclass of ; must not be a generic type definition ; ' s return type must be either or a subclass of .
The module's configuration is locked.
The module ' s configuration is locked .
None
None
controllerType
Type
The type of the controller.
The type of the controller .
factory
Func<WebApiController>
The factory method used to construct instances of .
The factory method used to construct instances of .
remarks
will be called once for each request to handle
in order to obtain an instance of .
The returned instance will be dereferenced immediately after handling the request. is not required to be thread-safe,
as it will be constructed and used in the same synchronization context.
However, since request handling is asynchronous, the actual execution thread
may vary during execution. Care must be exercised when using thread-sensitive
resources or thread-static data.If  implements ,
its Dispose return a newly-constructed instance of
at each invocation.If  does not implement ,
may employ techniques such as instance pooling to avoid
the overhead of constructing a new instance of
at each invocation. If so, resources such as file handles, database connections, etc.
should be freed before returning from each handler method to avoid
starvation
will be called once for each request to handle in order to obtain an instance of . The returned instance will be dereferenced immediately after handling the request . is not required to be thread - safe as it will be constructed and used in the same synchronization context . However since request handling is asynchronous the actual execution thread may vary during execution . Care must be exercised when using thread - sensitive resources or thread - static data . If implements its Dispose return a newly - constructed instance of at each invocation . If does not implement may employ techniques such as instance pooling to avoid the overhead of constructing a new instance of at each invocation . If so resources such as file handles database connections etc . should be freed before returning from each handler method to avoid starvation
seealso
None
seealso
None