pub fn fn_factory_with_config<F, Fut, Cfg, Srv, Req, Err>(
    f: F
) -> FnServiceConfig<F, Fut, Cfg, Srv, Req, Err>
where F: Fn(Cfg) -> Fut, Fut: Future<Output = Result<Srv, Err>>, Srv: Service<Req>,
Expand description

Create ServiceFactory for function that accepts config argument and can produce services

Any function that has following form Fn(Config) -> Future<Output = Service> could act as a ServiceFactory.

§Example

use std::io;
use ntex_service::{fn_factory_with_config, fn_service, Service, ServiceFactory};

#[ntex::main]
async fn main() -> io::Result<()> {
    // Create service factory. factory uses config argument for
    // services it generates.
    let factory = fn_factory_with_config(|y: &usize| {
        let y = *y;
        async move { Ok::<_, io::Error>(fn_service(move |x: usize| async move { Ok::<_, io::Error>(x * y) })) }
    });

    // construct new service with config argument
    let srv = factory.pipeline(&10).await?;

    let result = srv.call(10).await?;
    assert_eq!(result, 100);

    println!("10 * 10 = {}", result);
    Ok(())
}