pub fn register<T>(
        &mut self,
        implementation_factory: impl Fn(&Container) -> T + 'static + Send + Sync + Clone,
    ) -> &mut Self
    where
        T: 'static,
    {
        let registered_implementation_factory: Box<ImplementationFactory<T>> = {
            let implementation_factory = implementation_factory.clone();
            Box::new(move |container| implementation_factory(container))
        };
        self.registered_types.insert(
            type_name::<T>(),
            Arc::new(registered_implementation_factory),
        );

        let partially_applied_implementation_factory: Box<
            ImplementationFactory<Box<dyn Fn() -> T>>,
        > = Box::new(move |container: &Container| {
            let implementation_factory = implementation_factory.clone();
            let container = container.clone();
            Box::new(move || implementation_factory(&container))
        });

        self.registered_type_factories.insert(
            type_name::<Box<dyn Fn() -> T>>(),
            Arc::new(partially_applied_implementation_factory),
        );

        self
    }
/// Register a function that returns the implementation of a type.
/// Can be used to try_resolve dependencies.
///
/// # Examples
///
/// Registering a simple factory:
/// ```
/// use wonderbox::Container;
///
/// let mut container = Container::new();
/// container.register(|_| String::new());
/// ```
///
/// Registering a factory for a trait object with dependencies:
/// ```
/// use std::rc::Rc;
/// use wonderbox::Container;
///
/// let mut container = Container::new();
/// container.register(|_| "I'm a dependency".to_string());
/// container.register(|container| {
///     let dependency = container.try_resolve::<String>().unwrap();
///     let registered_type = FooImpl {
///         stored_string: dependency,
///     };
///     Box::new(registered_type) as Box<dyn Foo>
/// });
///
/// trait Foo {}
/// struct FooImpl {
///     stored_string: String,
/// }
/// impl Foo for FooImpl {}
/// ```
///
/// [`Clone`]: https://doc.rust-lang.org/std/clone/trait.Clone.html
Register a function that returns the implementation of a type.
Can be used to try_resolve dependencies.
Register a function that returns the implementation of a type . Can be used to try_resolve dependencies .
pub fn register<T>(
        &mut self,
        implementation_factory: impl Fn(&Container) -> T + 'static + Send + Sync + Clone,
    ) -> &mut Self
    where
        T: 'static,
    {
        let registered_implementation_factory: Box<ImplementationFactory<T>> = {
            let implementation_factory = implementation_factory.clone();
            Box::new(move |container| implementation_factory(container))
        };
        self.registered_types.insert(
            type_name::<T>(),
            Arc::new(registered_implementation_factory),
        );
        let partially_applied_implementation_factory: Box<
            ImplementationFactory<Box<dyn Fn() -> T>>,
        > = Box::new(move |container: &Container| {
            let implementation_factory = implementation_factory.clone();
            let container = container.clone();
            Box::new(move || implementation_factory(&container))
        });
        self.registered_type_factories.insert(
            type_name::<Box<dyn Fn() -> T>>(),
            Arc::new(partially_applied_implementation_factory),
        );
        self
    }
pub fn register < T > ( & mut self , implementation_factory : impl Fn ( & Container ) -> T + ' static + Send + Sync + Clone , ) -> & mut Self where T : ' static , { let registered_implementation_factory : Box < ImplementationFactory < T > > = { let implementation_factory = implementation_factory . clone ( ) ; Box :: new ( move | container | implementation_factory ( container ) ) } ; self . registered_types . insert ( type_name :: < T > ( ) , Arc :: new ( registered_implementation_factory ) , ) ; let partially_applied_implementation_factory : Box < ImplementationFactory < Box < dyn Fn ( ) -> T > > , > = Box :: new ( move | container : & Container | { let implementation_factory = implementation_factory . clone ( ) ; let container = container . clone ( ) ; Box :: new ( move | | implementation_factory ( & container ) ) } ) ; self . registered_type_factories . insert ( type_name :: < Box < dyn Fn ( ) -> T > > ( ) , Arc :: new ( partially_applied_implementation_factory ) , ) ; self }
Register a function that returns the implementation of a type.
Register a function that returns the implementation of a type .
&mut self
implementation_factory
impl Fn(&Container) -> T + 'static + Send + Sync + Clone
&mut self
implementation_factory
impl Fn(&Container) -> T + 'static + Send + Sync + Clone
examples
Registering a simple factory:
```
use wonderbox::Container.

let mut container = Container::new();
container.register(|_| String::new());
```

Registering a factory for a trait object with dependencies:
```
use std::rc::Rc;
use wonderbox::Container.

let mut container = Container::new();
container.register(|_| "I'm a dependency".to_string());
container.register(|container| {
let dependency = container.try_resolve::().unwrap();
let registered_type = FooImpl {
stored_string: dependency,
};
Box::new(registered_type) as Box
}).

trait Foo {}
struct FooImpl {
stored_string: String,
}
impl Foo for FooImpl {}
```


Registering a simple factory : ` ` ` use wonderbox :: Container . let mut container = Container :: new () ; container . register ( |_| String :: new () ) ; ` ` ` Registering a factory for a trait object with dependencies : ` ` ` use std :: rc :: Rc ; use wonderbox :: Container . let mut container = Container :: new () ; container . register ( |_| " I ' m a dependency " . to_string () ) ; container . register ( |container| { let dependency = container . try_resolve :: () . unwrap () ; let registered_type = FooImpl { stored_string : dependency } ; Box :: new ( registered_type ) as Box } ) . trait Foo {} struct FooImpl { stored_string : String } impl Foo for FooImpl {} ` ` `