the-moisrex / webpp

C++ web framework | web development can be done with C++ as well.
https://t.me/webpp
MIT License
132 stars 9 forks source link

Dependency Injection #52

Open the-moisrex opened 2 years ago

the-moisrex commented 2 years ago

An extension can specify the conditions that is required for a dependency to be constructed.

struct user {
  std::string username;
};

struct injector {
  template <Traits TraitsType, typename C>
  static constexpr bool can_inject = std::invocable_with<C, user>;

  static constexpr user construct_injection(Context auto&& ctx) {
    return user{
      .username = ctx.header('username')
    };
  }
};

It's just an example here.

the-moisrex commented 2 years ago

This issue has conflicts with #65

the-moisrex commented 1 year ago

Dependency Injection is possible using Custom Bodies.