diff --git a/src/darkleaf/di/core.clj b/src/darkleaf/di/core.clj index b1a63017..07acff10 100644 --- a/src/darkleaf/di/core.clj +++ b/src/darkleaf/di/core.clj @@ -651,19 +651,12 @@ (defn- stop-fn [variable] (-> variable meta (::stop (fn no-op [_])))) -(defn- validate-obj! [obj variable] - (when (nil? obj) - (throw (ex-info "A component fn must not return nil" - {:type ::nil-return - :variable variable})))) - (defn- var->0-component [variable] (let [stop (stop-fn variable)] (reify p/Factory (dependencies [_]) (build [_ _ add-stop] - (let [obj (variable)] - (validate-obj! obj variable) + (let [obj (?? (variable) ::nil)] (add-stop #(stop obj)) obj)) (description [_] @@ -676,8 +669,7 @@ (dependencies [_] deps) (build [_ deps add-stop] - (let [obj (variable deps)] - (validate-obj! obj variable) + (let [obj (?? (variable deps) ::nil)] (add-stop #(stop obj)) obj)) (description [_] diff --git a/test/darkleaf/di/component_test.clj b/test/darkleaf/di/component_test.clj index 9bbb947e..07bff793 100644 --- a/test/darkleaf/di/component_test.clj +++ b/test/darkleaf/di/component_test.clj @@ -15,12 +15,12 @@ nil) (t/deftest nil-component-0-arity-test - (let [ex (catch-some (di/start `nil-component-0-arity))] - (t/is (= ::di/nil-return (-> ex ex-cause ex-data :type))))) + (let [root (di/start `nil-component-0-arity)] + (t/is (= ::di/nil @root)))) (t/deftest nil-component-1-arity-test - (let [ex (catch-some (di/start `nil-component-1-arity))] - (t/is (= ::di/nil-return (-> ex ex-cause ex-data :type))))) + (let [root (di/start `nil-component-1-arity)] + (t/is (= ::di/nil @root)))) (defn component-2-arity