capydi
Loading...
Searching...
No Matches
Transient.hpp
Go to the documentation of this file.
1#ifndef CAPYDI_TRANSIENT_HPP_
2#define CAPYDI_TRANSIENT_HPP_
3
6#include "capydi/Error.hpp"
7
12#include <tuple>
13#include <expected>
14#include <vector>
15#include <memory>
16
17namespace capy::di
18{
19
20template<typename Type>
22 : public DecoratableConfig<
23 Transient<Type>
24 >
25{
26public:
27 using CentralType = Type;
28 using /* meta::Pack<meta::Pack<?>> */ ResolutionKeysPack = meta::Pack<
31 >;
32
33 using DependenciesPack = meta::args_pack_t<decltype(CentralType::create)>;
34
35public:
37
38public:
39 template<typename... Dependencies>
40 std::expected<meta::RuntimeRef<Type>, Error> do_resolve(
42 std::tuple<Dependencies...>& dependencies,
44 const auto& input
45 ) const
46 {
47 this->values_.push_back(std::make_unique<Type>(
48 std::apply(Type::create, dependencies)
49 ));
50
51 context.flags.just_created = true;
52
53 return meta::RuntimeRef<Type> { *this->values_.back() };
54 }
55
56 template<typename... Dependencies>
57 std::expected<meta::RuntimeRef<const Type>, Error> do_resolve(
59 std::tuple<Dependencies...>& dependencies,
61 const auto& input
62 ) const
63 {
65 this->do_resolve(meta::Pack<Type>{}, dependencies, input).value()
66 };
67 }
68
69 template<std::size_t DependencyIndex>
70 std::optional<std::tuple<>> get_dependencies_input() const
71 {
72 return std::nullopt;
73 }
74
75private:
76 mutable std::vector<std::unique_ptr<Type>> values_;
77};
78
79
80}
81
82#endif //CAPYDI_TRANSIENT_HPP_
Configuration type enumeration for the dependency injection system.
Error codes and diagnostics for dependency injection operations.
Compile-time type pack utilities and metaprogramming foundations.
Definition Transient.hpp:25
std::optional< std::tuple<> > get_dependencies_input() const
Definition Transient.hpp:70
std::expected< meta::RuntimeRef< const Type >, Error > do_resolve(meta::Pack< const Type > keys, std::tuple< Dependencies... > &dependencies, meta::wrapped_with< ResolutionContext > auto &context, const auto &input) const
Definition Transient.hpp:57
Type CentralType
Definition Transient.hpp:27
meta::Pack< meta::Pack< Type >, meta::Pack< const Type > > ResolutionKeysPack
Definition Transient.hpp:28
std::expected< meta::RuntimeRef< Type >, Error > do_resolve(meta::Pack< Type > keys, std::tuple< Dependencies... > &dependencies, meta::wrapped_with< ResolutionContext > auto &context, const auto &input) const
Definition Transient.hpp:40
static constexpr ConfigType CONFIG_TYPE
Definition Transient.hpp:36
meta::args_pack_t< decltype(CentralType::create)> DependenciesPack
Definition Transient.hpp:33
Definition RuntimeRef.hpp:13
Definition WrappedWIth.hpp:30
Definition Decorator.hpp:19
ConfigType
Categorization of configuration strategies in the DI container.
Definition ConfigType.hpp:24
@ CREATIONAL
Creational configs handle object instantiation and factory patterns. These are responsible for creati...
Definition ConfigType.hpp:27
Error
Enumeration of possible errors during dependency injection resolution.
Definition Error.hpp:26
typename function_traits< Function >::Params args_pack_t
Definition FunctionTraits.hpp:34
Definition DecoratableConfig.hpp:9
A compile-time heterogeneous type list.
Definition Pack.hpp:70