diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index f2a97e8..3fda518 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -69,7 +69,7 @@ struct ServiceContext { storage{ [&](std::index_sequence) -> utempl::Tuple { return {[&](utempl::Wrapper) { - return [&]() -> std::remove_cvref_t(storage))> { + return [&] -> std::remove_cvref_t(storage))> { return {utempl::Wrapper(names)>{}, *this}; }; }(utempl::Wrapper{})...}; @@ -202,12 +202,16 @@ public: static constexpr auto FindComponent() -> T&; template - static consteval auto GetDependencies() requires - requires {Magic(loopholes::Getter{}>{});} { - if constexpr(requires{GetDependencies();}) { - return GetDependencies{}>{}))::Type>(); + static consteval auto GetDependencies() requires (I == 0 || + requires {Magic(loopholes::Getter{}>{});}) { + if constexpr(I == 0 && !requires {Magic(loopholes::Getter{}>{});}) { + return utempl::TypeList{}; } else { - return utempl::kTypeList{}>{}))::Type>; + if constexpr(requires{GetDependencies();}) { + return GetDependencies{}>{}))::Type>(); + } else { + return utempl::kTypeList{}>{}))::Type>; + }; }; }; @@ -219,6 +223,16 @@ public: } // namespace impl +template +struct DependencyGraphElement {}; + + +template +struct DependencyGraph { + static constexpr auto kValue = utempl::TypeList{}; +}; + + template struct ServiceContextBuilder { static constexpr auto kList = utempl::kTypeList; @@ -257,6 +271,20 @@ struct ServiceContextBuilder { return config; }; + static consteval auto GetDependencyGraph() { + return [&] + (ComponentConfig...){ + return DependencyGraph + (ComponentConfig) { + impl::DependencyInfoInjector injector; + injector.template Inject(); + return injector.GetDependencies(); + }(Ts{})>...>{}; + }(Ts{}...); + }; + + static constexpr auto Run() -> void { [] (utempl::TypeList...>) {