boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.13k stars 137 forks source link

binder::resolve behavior inquiry #500

Open xilef opened 3 years ago

xilef commented 3 years ago

I am tracing the injector.create function until I reach this point in the code

  auto create_successful_impl__() const {
    auto&& dependency = binder::resolve<T, TName>((injector*)this);

How does resolve get TDefault even though it was not specified in the call?

  template <class T, class TName = no_name, class TDefault = dependency<scopes::deduce, aux::decay_t<T>>, class TDeps>
  static decltype(auto) resolve(TDeps* deps) noexcept {
    using dependency = dependency_concept<aux::decay_t<T>, TName>;

I am testing with a simple class with a simple call to create

class SingleClass {
public:
    SingleClass()
    {

    }

    ~SingleClass()
    {

    }
};

...

auto injector2 = di::make_injector();
SingleClass test = injector2.create < SingleClass>();

I am seeing TDefault has a proper dependency

boost::ext::di::v1_2_0::core::dependency<
    boost::ext::di::v1_2_0::scopes::deduce,
    SingleClass,
    SingleClass,
    boost::ext::di::v1_2_0::no_name,
    void,
    boost::ext::di::v1_2_0::core::none>

Where did TDefault come from?