pub fn get_resource_or_insert_with<T: Resource + Clone, F: FnOnce() -> T>(
        &mut self,
        f: F,
    ) -> T {
        if let Ok(resource) = self.get_resource::<T>() {
            return resource;
        }

        // No such resource, insert a new one.
        let resource = f();
        self.service
            .resources
            .insert(ResourceId::of::<T>(), Box::new(resource.clone()));
        tracing::info!(
            "Layer {} has created a new resource {}",
            self.layer,
            T::name()
        );
        resource
    }
Attempts to retrieve the resource of the specified type.
If the resource is not available, it is created using the provided closure.
core/lib/node_framework/src/service/context.rs