sealor: @Rollmops 
Thank you for your PR. Nice feature!

Does this implementation also work for factories where some default arguments are used and others not?
Could you please provide a test for this situation?
Rollmops: Good point! Should be resolved now.
sealor: I've squashed all commits into one and made some small improvements.
Are you fine with that?
Rollmops: Accepted 😄
diff --git a/junkie/core_context.py b/junkie/core_context.py
index 46baafd..6001fc1 100644
--- a/junkie/core_context.py
+++ b/junkie/core_context.py
@@ -1,5 +1,6 @@
 import inspect
 import logging
+from collections import OrderedDict
 from contextlib import contextmanager, ExitStack
 from typing import Union, Set, List, Dict, Callable, Tuple
 
@@ -68,8 +69,7 @@ class CoreContext:
             yield self._call(constructor, stack, constructor.__name__)
 
     def _call(self, factory_func: Callable, stack: ExitStack, instance_name: str):
-        arg_instances = []
-        arg_names = []
+        args = OrderedDict()
 
         for name, annotation in inspect.signature(factory_func).parameters.items():
             if name in self._instances:
@@ -78,14 +78,16 @@ class CoreContext:
             elif name in self._factories:
                 arg = self._call(self._factories[name], stack, name)
 
+            elif annotation.default is not inspect.Parameter.empty:
+                continue
+
             else:
                 raise Exception("Not found: " + name)
 
-            arg_instances.append(arg)
-            arg_names.append(name)
+            args[name] = arg
 
-        self.logger.debug("%s = %s(%s)", instance_name, factory_func.__name__, arg_names)
-        instance = factory_func(*arg_instances)
+        self.logger.debug("%s = %s(%s)", instance_name, factory_func.__name__, list(args.keys()))
+        instance = factory_func(**args)
 
         if hasattr(instance, "__enter__"):
             self.logger.debug("%s.__enter__()", instance_name)

Support default arguments
How to reproduce:

```
from junkie import Context

class Foo:
    def __init__(self, bar=None):
        self.bar = bar

context = Context({
    "foo": Foo
})

with context.build(Foo) as foo:
    pass
```

Current behaviour: `Exception: Not found: bar`

Expected behaviour: Since `bar` has a default value, one would expect using that default value if not found in the context.
diff --git a/test/core_context_test.py b/test/core_context_test.py
index 9c134ca..696be01 100644
--- a/test/core_context_test.py
+++ b/test/core_context_test.py
@@ -87,6 +87,36 @@ class CoreContextTest(unittest.TestCase):
 
             self.assertNotEqual(instance1, instance2)
 
+    def test_default_argument_usage(self):
+        class MyClassWithDefaultArguments:
+            def __init__(self, argument: str, default_argument: int = 10, default_argument2: str = None):
+                self.argument = argument
+                self.default_argument = default_argument
+                self.default_argument2 = default_argument2 or "Hello"
+
+        core_context = CoreContext()
+        core_context.add_instances({"argument": "value"})
+
+        with core_context.build_instance_by_type(MyClassWithDefaultArguments) as instance:
+            self.assertEqual("value", instance.argument)
+            self.assertEqual(10, instance.default_argument)
+            self.assertEqual("Hello", instance.default_argument2)
+
+    def test_partial_default_arguments_usage(self):
+        class MyClassWithDefaultArguments:
+            def __init__(self, argument: str, default_argument: int = 10, default_argument2: str = None):
+                self.argument = argument
+                self.default_argument = default_argument
+                self.default_argument2 = default_argument2 or "Hello"
+
+        core_context = CoreContext()
+        core_context.add_instances({"argument": "value", "default_argument2": "set from context"})
+
+        with core_context.build_instance_by_type(MyClassWithDefaultArguments) as instance:
+            self.assertEqual("value", instance.argument)
+            self.assertEqual(10, instance.default_argument)
+            self.assertEqual("set from context", instance.default_argument2)
+
     def test_context_manager_enter_and_exit(self):
         class Class:
             def __init__(self, message_service, database_context):

pip install -e .
parse_log_pytest
pytest
pytest
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
-e git+https://github.com/sealor/junkie.git@cae457a5131bb1c7cea020687076daa1edc7d13a#egg=junkie
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
pytest @ file:///croot/pytest_1738938843180/work
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work

name: junkie
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
prefix: /opt/conda/envs/junkie

test/core_context_test.py::CoreContextTest::test_default_argument_usage test/core_context_test.py::CoreContextTest::test_partial_default_arguments_usage
test/core_context_test.py::CoreContextTest::test_build_instance_by_dict_with_list_in_right_order test/core_context_test.py::CoreContextTest::test_build_instance_by_name test/core_context_test.py::CoreContextTest::test_build_instance_by_names test/core_context_test.py::CoreContextTest::test_build_instance_by_type test/core_context_test.py::CoreContextTest::test_context_manager_enter_and_exit test/core_context_test.py::CoreContextTest::test_factory_using_other_factory test/core_context_test.py::CoreContextTest::test_logging test/core_context_test.py::CoreContextTest::test_simple_factory test/core_context_test.py::CoreContextTest::test_simple_instance
junkie/core_context.py
junkie/core_context.py